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 > Programming Threads > Re: sup****ting...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 28 Topic 4066 of 4146
Post > Topic >>

Re: sup****ting header-less blocks in memory allocators...

by "Dmitriy V'jukov" <dvyukov@[EMAIL PROTECTED] > Oct 2, 2008 at 11:00 AM

On Oct 2, 8:29=A0pm, "Chris M. Thomasson" <n...@[EMAIL PROTECTED]
> wrote:

> But how could I efficiently intermingle large blocks and small blocks
fro=
m a
> single reserved memory pool?

In one of my programs I used following scheme:

template<typename derived_t>
class object_t
{
  static void* operator new (size_t sz)
  {
    // derived_t must be most derived type
    assert(sz =3D=3D sizeof(derived_t));
    // resolved at compile-time
    if (sizeof(derived_t) <=3D 4)
      return thread().fixed_alloc_4.alloc();
    else if (sizeof(derived_t) <=3D 8)
      return thread().fixed_alloc_8.alloc();
    else if (sizeof(derived_t) <=3D 16)
      return thread().fixed_alloc_8.alloc();
    else if (sizeof(derived_t) <=3D 32)
      return thread().fixed_alloc_8.alloc();
    [...]
    else
      return ::malloc(sizeof(derived_t));
  }

  static void operator delete (void* p)
  {
    // resolved at compile-time
    if (sizeof(derived_t) <=3D 4)
      thread().fixed_alloc_4.free(p);
    else if (sizeof(derived_t) <=3D 8)
      thread().fixed_alloc_8.free(p);
    else if (sizeof(derived_t) <=3D 16)
      thread().fixed_alloc_8.free(p);
    else if (sizeof(derived_t) <=3D 32)
      thread().fixed_alloc_8.free(p);
    [...]
    else
      ::free(p);
  }
};


Dmitriy V'jukov
 




 28 Posts in Topic:
supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 07:28:39 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 07:30:14 
Re: supporting header-less blocks in memory allocators...
Eric Sosman <Eric.Sosm  2008-10-02 10:55:36 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 10:17:04 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 14:47:48 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 08:41:31 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 09:29:16 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 11:00:02 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 11:50:57 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 11:55:02 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:20:25 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:30:51 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 12:00:46 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:30:09 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:38:26 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:48:45 
Re: supporting header-less blocks in memory allocators...
Michel Decima <michel.  2008-10-03 13:56:34 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 12:07:41 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-03 22:41:41 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-02 12:24:01 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:32:18 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-02 12:35:16 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-03 03:40:04 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-03 03:42:50 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-03 05:52:20 
Re: supporting header-less blocks in memory allocators...
Michel Decima <michel.  2008-10-03 15:28:13 
Re: supporting header-less blocks in memory allocators...
"Chris M. Thomasson&  2008-10-03 22:19:59 
Re: supporting header-less blocks in memory allocators...
"Dmitriy V'jukov&quo  2008-10-06 00:02:32 

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 Nov 22 9:01:16 CST 2008.