This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C++ STL memory allocation to selected memory segment

Hello,

I'm using CGT  6.1.15 and DSP/BIOS 5.33.06 on different C6000 DSPs.

For most parts of the application the STL containers have to be allocated in external memory. Selected containers need to allocated their memory in internal memory. To prevent a copy of the data these containers are passed by reference. Is there a solution to allocate memory within the specified memory segment for those containers without changing the container type?

As a workaround I currently use a custom allocator and cast the container to the container type with the default allocator. Unfortunately this will fail badly as soon as somebody in the system that does not know about my changed container type is modifiying this container. The solution should work with the default allocator.

Thanks!

 

  • Elmar Damrau said:
    Is there a solution to allocate memory within the specified memory segment for those containers without changing the container type?

    No.  This is a problem with C++ itself, and we can do nothing about it.  This long conversation with Alexander Stepanov (the main author of the STL) talks about it.  Search for "allocator" to find it quickly.  Basically, the allocator is part of the type for objects created with that allocator.  Thus, objects created with different allocators are different types, and cannot mix together freely.

    Thanks and regards,

    -George