Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Shared-memory pool's size #568

Open
owny990312 opened this issue Dec 24, 2024 · 5 comments
Open

Adjust Shared-memory pool's size #568

owny990312 opened this issue Dec 24, 2024 · 5 comments

Comments

@owny990312
Copy link

owny990312 commented Dec 24, 2024

Adjust Shared-memory pool's size like iceoryx1, we have a .toml file to set the shm-pool's size. Or iceoryx2 can auto-adjust it

@owny990312 owny990312 changed the title Adjust Shared-memory poll's size Adjust Shared-memory pool's size Dec 24, 2024
@elBoberido
Copy link
Member

In iceoryx2 it's not necessary anymore. Each publisher has it's own mempool and the number of memory chunks are inferred from the confiuration of the service.

@owny990312
Copy link
Author

In iceoryx2 it's not necessary anymore. Each publisher has it's own mempool and the number of memory chunks are inferred from the confiuration of the service.在 iceoryx2 中不再需要这样做。每个发布者都有自己的 mempool,内存块的数量是从服务的配置中推断出来的。

Thanks for your reply. I also want to ask: there are three method to write data in a shared-memory,

inline void SampleMutUninit<S, Payload, UserHeader>::write_payload(T&& value)
inline void SampleMutUninit<S, Payload, UserHeader>::write_from_fn(const iox::function<typename T::ValueType(uint64_t)>& initializer)
inline void SampleMutUninit<S, Payload, UserHeader>::write_from_slice(iox::ImmutableSlice& value)

Is there a C++ API similar to iceoryx1 where I can manually loan shared memory of a desired size and release it through explicit user calls? In iceoryx1 I use

iox_pub_loaned_shm_ptr = iox_pub->loan(loan_size) to loan shared memory of a desired size
iox_pub->release(iox_pub_loaned_shm_ptr) to release it.

am confused about the lifecycle of shared memory

@orecham
Copy link
Contributor

orecham commented Dec 25, 2024

@owny990312

Is there a C++ API similar to iceoryx1 where I can manually loan shared memory of a desired size

For this use-case, the Slice payload type should be used (representing an arbitrarily sized chunk of memory).

Take a look at this example: https://github.com/eclipse-iceoryx/iceoryx2/blob/main/examples/cxx/publish_subscribe_dynamic_data/src/publisher.cpp#L55

Note that you can also access a pointer to the shared memory via something like:

auto sample = publisher.loan_slice_uninit(required_memory_size).expect("acquire sample");
auto ptr = sample.payload().data();

You can then do a placement new, or populate the bytes via any other mechanism, but you have the ensure not to exceed the loaned size yourself, so it is safer to use one of the provided methods that you listed.

release it through explicit user calls

The sample is released when it goes out of scope through RAII mechanisms. You can also manually destruct the sample to achieve this.

@owny990312
Copy link
Author

owny990312 commented Dec 25, 2024

@owny990312

Is there a C++ API similar to iceoryx1 where I can manually loan shared memory of a desired size

For this use-case, the Slice payload type should be used (representing an arbitrarily sized chunk of memory).对于这个用例,应该使用Slice负载类型(表示任意大小的内存片段)。

Take a look at this example: https://github.com/eclipse-iceoryx/iceoryx2/blob/main/examples/cxx/publish_subscribe_dynamic_data/src/publisher.cpp#L55查看这个示例:https://github.com/eclipse-iceoryx/iceoryx2/blob/main/examples/cxx/publish_subscribe_dynamic_data/src/publisher.cpp#L55

Note that you can also access a pointer to the shared memory via something like:

auto sample = publisher.loan_slice_uninit(required_memory_size).expect("acquire sample");
auto ptr = sample.payload().data();

You can then do a placement new, or populate the bytes via any other mechanism, but you have the ensure not to exceed the loaned size yourself, so it is safer to use one of the provided methods that you listed.你可以然后使用 placement new 进行初始化,或者通过其他机制填充字节,但你需要确保不要超过借用的大小,因此使用你列出的其中一个提供的方法会更安全。

release it through explicit user calls通过显式用户调用释放它

The sample is released when it goes out of scope through RAII mechanisms. You can also manually destruct the sample to achieve this.The sample 是在超出作用域时通过 RAII 机制释放的。你也可以手动销毁样本以实现这一点。

I have a question about DDS sample lifecycle management. In a distributed scenario where Process A publishes data and Process B subscribes to it, if the sample is released when it goes out of scope in the publisher's function, will this affect the subscriber's ability to receive the data?
Additionally, how can I manually destruct the sample?

@elfenpiff
Copy link
Contributor

@owny990312 The subscriber can consume the sample if it holds the Sample object. When it goes out of scope, it is released - this is completely independent of the publisher.

Additionally, how can I manually destruct the sample?

Just let the sample go out of scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants