Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Using speci...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 8 Topic 45810 of 47034
Post > Topic >>

Re: Using special allocator interfaces...

by "Chris Thomasson" <cristom@[EMAIL PROTECTED] > May 8, 2008 at 10:03 PM

"Chris Thomasson" <cristom@[EMAIL PROTECTED]
> wrote in message 
news:6YadndjqnMtxkL7VnZ2dnUVZ_rSrnZ2d@[EMAIL PROTECTED]
> "Alf P. Steinbach" <alfps@[EMAIL PROTECTED]
> wrote in message
[...]



> // Can I use the above allocator interface like this:
> template<typename T>
> struct AllocatorBlock {
>  unsigned char mBuffer[sizeof(T)];
>  Allocator::Region* mRegion;
>
>  static void* MemRequest() {
>    Allocator::Region* region;
>    AllocatorBlock* const block = (AllocatorBlock*)
>      Allocator::MemRequest(&region, sizeof(T));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


This is in ERROR!

    The size is all wrong on a per-object basis; here is correction:


    AllocatorBlock* const block = (AllocatorBlock*)
      Allocator::MemRequest(&region, sizeof(*block));
    block->mRegion = region;
    return block->mBuffer;


    sizeof(T) is not sufficient, however sizeof(*block) is.




>    block->mRegion = region;
>    return block->mBuffer;
>  }
>
>  static void MemRelease(void* ptr) {
>    AllocatorBlock* const block = (AllocatorBlock*)ptr;
>    Allocator::MemRelease(block->mRegion, ptr, sizeof(T));
>  }
> };





[...]

Strange that I did not get flamed for this yet!


;^D
 




 8 Posts in Topic:
Using special allocator interfaces...
"Chris Thomasson&quo  2008-05-08 06:20:47 
Re: Using special allocator interfaces...
"Alf P. Steinbach&qu  2008-05-08 15:24:33 
Re: Using special allocator interfaces...
"Chris Thomasson&quo  2008-05-08 06:44:06 
Re: Using special allocator interfaces...
"Alf P. Steinbach&qu  2008-05-08 16:00:06 
Re: Using special allocator interfaces...
"Chris Thomasson&quo  2008-05-08 07:30:35 
Re: Using special allocator interfaces...
"Chris Thomasson&quo  2008-05-08 22:03:09 
Re: Using special allocator interfaces...
"Chris Thomasson&quo  2008-05-09 15:34:04 
Re: Using special allocator interfaces...
Daniel Pitts <newsgrou  2008-05-08 08:12:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:01:14 CDT 2008.