a light breeze said:
ook at boost::static_vector and boost::small_vector. The former is a fixed-capacity version of std::vector that avoids dynamic allocation entirely. You could use it to replace your array of ten vectors.
I might accept some workaround for the array problem. But the array is just a example. What i really want is decoupling object creation and initialization. Eventually i want to create the objects from a single thread which loads them from disk, and i may want to initialize them later from parallel jobs.
Objects which require a non default constructor to work are thus bad design in most cases.
At least for something general like std::vector, that's bad design for sure.
They tried to fix this. Only since C++11 STL allocators can have some state, e.g. to assign different vectors to different memory pools. And technically everything would indeed work now.
But we are forced to construct every object, meaning creation and initialization has to happen at the same time.
This constraint is not acceptable. They failed, and now they have to try again.
The flaw is already rooted in the C++ language.
Why does making an array of vectors call their default constructors, but there is no way to call parametrized constrictors?
Placement new addresses the latter, but the former is still a problem requiring a fix.
frob said:
How much profiling have you done regarding memory use? Are you reserving blocks properly? Have you initialized containers to their expected size? Have you looked at the code triggering reallocations to verify it makes sense?
I did what i can. Always reserving, minimizing allocations in any way, profiling, etc.
Still it was a matter of years to come to the final conclusion about allocation being the culprit.
I can't be 100% sure yet, but i bet a beer that custom memory management will prevent the performance degradation over time completely. Might be a week of work to pert everything to EASTL and adding the management, but i'll report the outcome…
frob said:
Constructors generally are not the problem. Misuse might be.
Hehe, well - it took me the whole yesterday to figure out how to attach my allocator to EASTL vectors.
My mistake was to copy paste empty copy constructors from the given stateless code examples.
So yeah, mistakes on my side are quite likely. :D
dpadam450 said:
Not sure what you are doing or trying to solve it, but caches are pretty big and good use. Since it's a vector that re-allocates, its core memory is not going to live near your vector object anyway. …
Yes, yes. Workarounds are possible, and they may be acceptable.
But we should not defend the broken status quo by discussing which workaround is the least evil.
We should complain about the broken status quo, so they will fix it in the future.
With EASTL i can do exactly what i want:
eastl::vector<int, eastlAlloc> vecCustomN[10];
for (auto &a : vecCustomN) a.set_allocator(myCustomAlloc);
vecCustomN[5].resize(3,-1);
vecCustomN[5][1] = 1;
vecCustomN[5].push_back(3);
for (auto &v : vecCustomN[5]) ImGui::Text("vecCustomN[5]: %i", v);
vecCustomN[5].clear();
vecCustomN[5].set_capacity(0);
Creating the array of empty vectors does not yet create a bogus element just to make their implementation work. They do not allocate anything until we say so.
I can (thus) set the allocator after the object creation, at any time when i'm ready to do so.
They did all this work because they were not happy with the status quo either.
And i can even read and learn from the code. STL is just cryptic random letters to my eyes.
So that's the proper solution for me i guess. Will report my experience…