开发者

static allocated data structures

开发者 https://www.devze.com 2023-01-20 15:19 出处:网络
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

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 n开发者_JAVA技巧o 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?


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消