WIP added simple usage test ... and made it compile,
but still a fundamental problem to resolve with the use of std::vector in this scenario
This commit is contained in:
parent
6bd0c84355
commit
89fca1921d
2 changed files with 35 additions and 6 deletions
|
|
@ -63,8 +63,8 @@ namespace lib {
|
|||
size_t top_;
|
||||
|
||||
public:
|
||||
MemoryManager(TypeInfo info) { reset(info); }
|
||||
~MemoryManager() { purge(); }
|
||||
MemoryManager(TypeInfo info) : top_(0) { reset(info); }
|
||||
~MemoryManager() { purge(); }
|
||||
|
||||
void purge();
|
||||
void reset(TypeInfo info);
|
||||
|
|
@ -102,7 +102,7 @@ namespace lib {
|
|||
|
||||
while (top_)
|
||||
type_.killIt (&mem_[--top_]);
|
||||
mem_.resize(0);
|
||||
mem_.clear();
|
||||
}// note: unnecessary to kill pending allocations
|
||||
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ namespace lib {
|
|||
for (size_t i = typeHandlers_.size(); 0 < i; --i)
|
||||
handler(i)->purge();
|
||||
|
||||
typeHandlers_.resize(0);
|
||||
typeHandlers_.clear();
|
||||
|
||||
}
|
||||
catch (lumiera::Error & ex)
|
||||
|
|
@ -203,7 +203,7 @@ namespace lib {
|
|||
Thread::Lock<AllocationCluster> guard SIDEEFFECT; /////TODO: decide tradeoff: lock just the instance, or lock the AllocationCluster class?
|
||||
|
||||
if (slot > typeHandlers_.size())
|
||||
typeHandlers_.resize(slot);
|
||||
typeHandlers_.resize(slot); /////////////////////////////TODO: still a fundamental problem buried here with the way stl::vector grows...
|
||||
if (!handler(slot))
|
||||
handler(slot).reset (new MemoryManager (type));
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace lib {
|
|||
char content[i];
|
||||
|
||||
public:
|
||||
Dummy (char id)
|
||||
Dummy (char id=1)
|
||||
{
|
||||
content[0] = id;
|
||||
checksum += id;
|
||||
|
|
@ -75,6 +75,8 @@ namespace lib {
|
|||
{
|
||||
checksum -= content[0];
|
||||
}
|
||||
|
||||
char getID() { return content[0]; }
|
||||
};
|
||||
|
||||
typedef ScopedHolder<AllocationCluster> PCluster;
|
||||
|
|
@ -149,10 +151,37 @@ namespace lib {
|
|||
if (1 < arg.size()) NUM_OBJECTS = lexical_cast<uint> (arg[1]);
|
||||
if (2 < arg.size()) NUM_FAMILIES = lexical_cast<uint> (arg[2]);
|
||||
|
||||
simpleUsage();
|
||||
checkAllocation();
|
||||
checkErrorHandling();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
simpleUsage()
|
||||
{
|
||||
AllocationCluster clu;
|
||||
|
||||
char c1(123), c2(56), c3(3), c4(4), c5(5);
|
||||
Dummy<44>& ref1 = clu.create<Dummy<44> > ();
|
||||
Dummy<37>& ref2 = clu.create<Dummy<37> > (c1);
|
||||
Dummy<37>& ref3 = clu.create<Dummy<37> > (c2);
|
||||
Dummy<1234>& rX = clu.create<Dummy<1234> > (c3,c4,c5);
|
||||
|
||||
ASSERT (&ref1);
|
||||
ASSERT (&ref2);
|
||||
ASSERT (&ref3);
|
||||
ASSERT (&rX);
|
||||
TRACE (test, "sizeof( Dummy<1234> ) = %d", sizeof(rX));
|
||||
|
||||
ASSERT (123==ref2.getID());
|
||||
ASSERT (3+4+5==rX.getID());
|
||||
// shows that the returned references actually
|
||||
// point at the objects we created. Just use them
|
||||
// and let them go. When clu goes out of scope,
|
||||
// all created objects dtors will be invoked.
|
||||
}
|
||||
|
||||
void
|
||||
checkAllocation()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue