2

I'm working on a existing embedded system (memory is limited, Flash is limited, ...) with an RT OS. All data structures have a fixed size and are allocated at "compile time" and are therefore suited for RT. There is no dynamic memory allocation. The programming language is C++, but there is no STL available. I like to replace some of the data structures especially LinkedList, Vector and Map with some more generic variants.

The closest I've seen so far is the following framework: http://apfw.sourceforge.net/. The biggest draw back IMHO is that the for a LinkedList with size N, the default constructor from T is called N times. A better class should statically allocate sizeof(T)*N bytes.

Does anyone know I library with all of the above constraints?

azraiyl
  • 343
  • 2
  • 4
  • 11
  • It most likely allocates the storage statically in the image. But C++ requires the ctors to be called. How else would you want it to initialize the T instances? – wilx Oct 19 '10 at 11:43
  • If this framework supports custom allocators you could try to write your own allocator. – sellibitze Oct 19 '10 at 11:48
  • @sellibitze. Custom allocators are not supported. – azraiyl Oct 19 '10 at 11:49
  • 1
    @wilx. First the byte constructor is called. Later the objects are added through a placement new. At least that was the first thing going through my head, if I've to implement something. – azraiyl Oct 19 '10 at 11:50
  • @wilx: The same way `std::vector` does this. Its capacity is all raw bytes, with constructors invoked (via placement new) as necessary. – sbi Oct 19 '10 at 12:05

3 Answers3

1

If you are fixing the size of the LinkedList, why not just create your own simple class and back it by an array?

Anon
  • 1,290
  • 2
  • 16
  • 24
  • Because there are maybe 10% of the methods needed, compared what the STL provides, that would be feasible. I guess if no one already knows a library I'll write my own class, post it here, and let the experts decide, what I f..... up. – azraiyl Oct 19 '10 at 11:45
1

Have you considered passing your own allocator (allocating from a static pool) to STL containers?

Other than that, I don't think anything like this exists. You might want to look at this related question to get started with a static vector class. If you do this, consider to make it Open Source.

Community
  • 1
  • 1
sbi
  • 219,715
  • 46
  • 258
  • 445
  • Currently the target has no STL. If there was enough Flash available (the download link is a serial line with ca. 2 KiBytes/s, therefore even if I add more Flash I've a problem) I guess the STL with an O(1) memory allocator (e.g. http://rtportal.upv.es/rtmalloc/) would be ok. I've to admit that I never tried to chop up the STL in small pieces. – azraiyl Oct 19 '10 at 12:27
1

May I recommend you the following:

http://www.codeproject.com/KB/recipes/Containers.aspx

It's an article I've written about anoter design of container classes. One of the biggest advantages of them is that allocating the data and storing it in the container are separated.

You may for instance declare your static data at compile-time, and then in run-time insert/remove it to/from the list/tree/etc.

valdo
  • 12,632
  • 2
  • 37
  • 67