optional reduction of overhead for classes

clayasaurus clayasaurus at gmail.com
Mon Apr 17 08:03:25 PDT 2006


With pointer = 4 bytes and float = 4 bytes...
------------------------------------------------

I'm trying to figure out a way I can have a class and give it the option 
to include less overhead, my idea goes something like this...

Entity e = new Entity(); // Independent
Entity e = new Entity(DEPENDENT);

class Entity
{
    this()
    {
        // allocate new resources of (4+4=8 bytes?)
        data = new EntityData;
    }

    this(int type)
    {
        assert(type == DEPENDENT);
    }

    void draw()
    {
       glDraw(data.x, data.y);
    }

    void drawAt(x, y)
    {
       glDraw(x,y);
    }

    EntityData data; // a class
}

class EntityData
{
   float x, y;
}

------------------------------------------------------------------------

My question is, how much memory does EntityData use before allocation 
(4-bytes?), and how much does it use after allocation (4+4+4 bytes total?).

Thanks.
~ Clay









More information about the Digitalmars-d-learn mailing list