Re: Sequence allocation of inner objects
Duncan Grisby via omniORB-list <[email protected]>
| Newsgroups | gmane.comp.corba.omniorb.user |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 2017-06-03 at 09:10 +0200, Thierry Descombes via omniORB-list wrote: > We have developed a software for embedded data acquisition. We have > little resources. We use omniORB to send data containing a CORBA > sequence of AdcEventData objects : > > typedef sequence <AdcEventData> SeqAdcEventData > > The AdcEventData object itself contains sequences and a big structure > of informations. To process / sort this information, we need to break > this SeqAdcEventData to extract all of the AdcEventData. To be precise, I don't think you mean AdcEventData is an "object", which in CORBA would generally mean an object reference, declared in IDL with "interface". I think you mean it is a struct. > Currently, we are calling a function to create a new copy of the > AdcEventData: > > addAdc(new AdcEventData ((* s) [i])); // for each elem of the > sequence > > ... > And then, we delete the sequence (that frees all inner AdcEventData > objects)... but it consumes lot of unnecessarily resources on our > small embedded CPU. > Is there a good solution for not having to re-instantiate and copy > the AdcEventData ? Could we just copy pointer's (AdcEventData*) > values, and then fix the sequence length to 0 before calling delete > on it ? Not exactly. The C++ mapping for a sequence of structs requires that the sequence uses an array of the structs in its internal buffer, not an array of pointers to structs. You therefore can't get the pointers of the sequence members and manage them separately, because the structs are all allocated in a single big buffer. You can, however, extract the buffer of structs from the sequence and manage its lifecycle yourself. You can call the standard get_buffer method on the sequence, settings the "orphan" parameter to true. That transfers ownership of the buffer to you, meaning that when the sequence object is deleted, it does not free the buffer. You have to free it yourself later. The C++ mapping specification says you have to free it by calling the sequence type's freebuf() function, but in omniORB that's just a call to delete[], so you could directly delete[] it. If that isn't sufficient for you, you could resort to customising the generated code. If you put the IDL sequence definition in its own separate IDL file, then you could quite easily provide a different implementation of the C++ sequence type that managed the members as an array of pointers. Look in include/omniORB4/seqTemplatedecls.h for the definition of the _CORBA_Sequence template to see how it's implemented. Duncan. -- -- Duncan Grisby -- -- [email protected] -- -- http://www.grisby.org -- _______________________________________________ omniORB-list mailing list [email protected] http://www.omniorb-support.com/mailman/listinfo/omniorb-list