-
Notifications
You must be signed in to change notification settings - Fork 791
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
Memory allocation improvements #344
Comments
@dejanpan FYI, work in progress |
@richiware, @MiguelCompany:
Would it make sense to replace the |
This is going to be part of Fast-RTPS internals, thus we are only providing the functionality that is currently being used in the code of Fast-RTPS. We don't plan to export this as a general-purpose library.
I agree. The idea for other containers, like
You can check the implementation on #386. It cannot have a fixed size, as we want the user to configure the allocation behavior by setting values on participant, writer and reader attributes. Regarding the non-copyable pattern, as we may have items of a vector having vectors inside, we may sometimes need them to be copied. |
This use case is not clear to me. I would say users accept or do not accept memory allocation during steady time. Can you explain me the use case for initial < maximum in #386. |
The user may accept memory allocation on steady time, but have some knowledge about typical values, thus wanting to configure an initial allocation on creation. For instance, if we have 50 robots in a big warehouse, but we know that typically only 10 are within communication range, we may use an initial value of 10 and a maximum value of 50. |
@MiguelCompany: Why should he not reserve 50 in the first place? Memory usually never freed from a vector, Just trying to understand the exact requirement. |
@deeplearningrobotics: You may be right for the case I exposed. But there is at least one other case which is not having a maximum limit but having an initial reserved value. In commit 65ee6a065181ba499ee546277e907fac90605a06, I have added the configuration struct as a template parameter, so if we consider it necessary in the future, we could specialize the template for a size_t on that parameter and then use an implementation based on std::array. |
For fixed size string and vectors, have you considered using the embedded template library? https://www.etlcpp.com/string.html. It seems like a great opportunity to capitalize on an existing project that could be re-used by others as well. |
To be able to use this product in critical systems, the product must not be allowed to allocate or free memory during its execution.
It has to either use static memory or allocate the memory at the creation of the entities (participant, writer, reader...).
We can describe the following formal requirement:
Basic strategy
Resource-limited STL containers
There are several places where the number of elements present on STL containers depends on the discovered number of participants/publishers/subscribers.
For these cases, several approaches may be considered:
All these options are compatible and can be addressed one on top of the other.
The first one provides control over the number of elements to be used in the internal data collections and can be designed with an API similar to other QoS of the product.
The second one would allow the user to control the total amount of memory to be used in an easy way but would add an additional dependency to the project.
The third one would provide the most flexibility but would imply to spread the traits through a high number of classes.
As DDS compliance API is on our roadmap, we will leave the decision for the third approach until we address that feature, and start with the first approach only.
The STL wrappers would be ready for the other approaches, having the corresponding traits on the wrapping container and the allocator used.
This strategy will be used for every
std::vector<GuidPrefix_t>
,std::vector<ParticipantProxyData*>
,std::vector<WriterProxyData*>
,std::vector<WriterProxy*>
,std::vector<RemoteWriterAttributes>
,std::vector<ReaderProxyData*>
,std::vector<ReaderProxy*>
,std::vector<RemoteReaderAttributes>
,std::vector<ChangeForReader_t>
,std::vector<ChangeFromWriter_t>
,std::vector<Locator_t>
,std::set<RTPSWriter*>
and the maps onRTPSReader
.Specific design below
Strings and other STL containers
std::string
attributes onParticipantProxyData
,ReaderProxyData
andWriterProxyData
will be transformed intofixed_string<255>
.std::vector<SequenceNumber_t>
onSequenceNumberSet_t
and thestd::vector<FragmentNumber_t>
onFragmentNumberSet_t
will be transformed into bitmaps of a static size.ParameterList_t
and itsstd::vector<Parameter_t*>
will be removed.std::vector<uint32_t>*
onCacheChange_t
, thestd::unordered_multiset
onFragmentedChangePitStop
and thestd::set<FragmentNumber_t>
onChangeForReader_t
will be removed as part of the fragment management refactor.RTPSWriterCollector
and itsstd::set<RTPSWriterCollector::Item>
will be removed as part of the flow controllers refactor.std::string
andstd::vector
onProperty
,BinaryProperty
andPropertyPolicy
classes will be removed as part of the properties refactor.Specific design
Resource limited collections [#386, #406, #423, #479]
A new struct
ResourceLimitedContainerConfig
withinitial
,maximum
andincrement
fields of typesize_t
. Setting the same value oninitial
andmaximum
will define a preallocated policy.Several QoS policies of type
ResourceLimitedContainerConfig
will be added:matchingReaderNumberQos
onWriterAttributes
matchingWriterNumberQos
onReaderAttributes
remoteParticipantNumberQos
onRTPSParticipantAttributes
readerNumberQos
onRTPSParticipantAttributes
writerNumberQos
onRTPSParticipantAttributes
A wrapper of
std::vector
will be developed:Only need following functionality:
ResourceLimitedContainerConfig
T* push_back()
(copy and move) andT* emplace_back(...)
bool remove(const T&)
andbool remove_if(predicate)
begin
,end
empty
,clear
,size
,capacity
Fixed size strings [#361]
A
template<size_t N> fixed_string
class containing an array ofN + 1
characters will be developed.Only basic operations are necessary:
const char*
/std::string
const char*
/std::string
fixed_string
/const char*
/std::string
fixed_string
/const char*
/std::string
Fixed size bitmaps [#370]
A
template<class T, size_t NBITS=256> BitmapRange
class will be developed.Type T is required to behave like an unsigned integer type, and shall at least have addition with
size_t
,post-increment and comparison operators.
The
BitmapRange
class will have the following fields:Required functionality:
explicit BitmapRange(const T& base)
bool add(const T& item)
void bitmap_get(size_t& num_bits, bitmap_type& bitmap, size_t& num_longs_used)
void bitmap_set(size_t num_bits, const uint32_t* bitmap)
Removing ParameterList_t [#379]
All
*ProxyData
classes will have abool writeToCDRMessage(CDRMessage_t* msg, bool write_encapsulation)
method instead of their currentAllQostoParameterList
ortoParameterList
, that will create each Parameter_t as a local variable and serialize it directly on the destination message.This is consistent with their current
readFromCDRMessage
method and avoids the use of aParameterList_t
The signature of
ParameterList::readParameterListfromCDRMsg
will be changed tobool readParameterListfromCDRMsg(CDRMessage_t* msg, std::function<void (const Parameter_t*)> processor, bool use_encapsulation, uint32_t& qos_size)
.It will parse each of the parameters received on the message using local variables (stack allocated) and pass each of them to the function received.
New
bool ParameterList::updateCacheChangeFromInlineQos(rtps::CacheChange_t& change, rtps::CDRMessage_t* msg, uint32_t& qos_size)
method that will directly parse the received inline qos, parameter by parameter.Flow controllers refactor
Current interface on flow controllers is as follows:
We want to get rid of RTPSWriterCollector by changing the interface to:
Class
RTPSWriter
will have aResourceLimitedVector<ChangeForReader_t>
with the queue of changes pending to be sent, and child classesStatelessWriter
andStatefulWriter
will manage the queue accordingly.The resource limits configuration of the pending queue will be automatically calculated based on the resource limits of the writer's history.
The text was updated successfully, but these errors were encountered: