|
-
March 7th, 2012, 07:27 AM
#16
Re: Custom allocator problems
 Originally Posted by JohnW@Wessex
The idea was that different vectors wouldn't use the same allocator instance.
I understand, but the vector implementation cannot assume that. It seems very reasonable to me that when an implementation asks for two allocations without deallocating in between that it requires to receive non-overlapping memory ranges from the allocator.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
March 8th, 2012, 04:14 AM
#17
Re: Custom allocator problems
I think what really bugs me is that, as my allocators used to work OK under VS2008, it must be possible to produce an STL container that is compatible with allocators that contain their own storage.
BTW My original allocators worked with raw byte storage, aligned to the type, rather than an array of actual objects that my simplified example used.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
March 8th, 2012, 05:13 AM
#18
Re: Custom allocator problems
 Originally Posted by JohnW@Wessex
I think what really bugs me is that, as my allocators used to work OK under VS2008, it must be possible to produce an STL container that is compatible with allocators that contain their own storage.
actually, the issue in c++03 was even worse because implementations were allowed to always consider equal allocator instances of the same type ( copy constructed or not ). So, even an allocator storing a pointer to an external arena was at least non portable in c++03.
anyway, an easy workaround to adapt your existing code to work with vs2010 is to make the allocator fallback to the heap when constructed from an allocator of different type (eg. the template copy constructor). Given that auxillary allocators are used for debugging purpose only ( at least in std::vector and std::list, I'm not sure for set/map ) you should recover the expected stack-only allocation behavior on release builds.
Clearly, this solution is not portable ...
-
March 8th, 2012, 06:15 AM
#19
Re: Custom allocator problems
 Originally Posted by superbonzo
anyway, an easy workaround to adapt your existing code to work with vs2010 is to make the allocator fallback to the heap when constructed from an allocator of different type
Unfortunately, that goes against my design requirements. Although the code is compiled and run on Windows for simulation purposes, the final application runs on a DSP platform with a lot less resources.
The object was to create an efficient allocator that could be used for STL containers on a memory restricted, time critical platform. The fixed storage overhead needed to be defined and placed in specified memory regions at compile time.
This would be especially useful when using std::list and other such containers where the storage cannot normally be reserved upfront.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
March 8th, 2012, 06:48 AM
#20
Re: Custom allocator problems
You guys have me kind of lost, so I might be saying something stupid. The problem only occurs when objects from one container are swapped to another container that uses a different allocator, right?
Rather than re-code entire containers, isn't it possible to explicitly compare the allocators outside of the containers, and swap by value if the allocators are different?
Maybe stl containers don't explicitly support this, but that doesn't mean you can't add the support yourself explicitly via a new traits?
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|