Re: Re[2]: [CODE][OLC][?] Deleting

From: Ron Cole (roncole@SHORE.INTERCOM.NET)
Date: 07/28/97


>  Okay, perhaps I'm missing something.
>
>  Boolean variables only hold values of 0 or 1... thus, they should
>require only one bit of memory... correct?  That seems minimal enough.

Yes, but you can't allocate a single bit of memory.  The least you could
allocate is a byte.  If your structure already fit nicely into say, 64 bytes of
memory, and you're particular OS/Hardware combo allocates memory on 8 byte
boundaries, you've just effectively added 8 bytes of memory to your struct for
one bit.  If you're in a position where you have to closely monitor memory
resources, it really pays to learn how your machine works, so you can align your
data to take advantage of it.  The order of the fields is critical too.  The
following exampt struct could take twice as much memory or more than you are
actually using on most 32 bit platforms.

struct waste {
  char byte_field;
  long int_field;
  char byte_field2;
}

The first field wastes 3 bytes, since long ints are usually aligned on 4 byte
boundaries.  The third field then takes 1 extra byte, making it a total of 9
bytes, so, memory allocated on 8 byte boundaries, will skip the remaining 7.
So, we have 16 bytes used for 6 bytes of data.  Moving the second char field to
back to before the long will save you 8, and you could still insert 2 more char
fields or perhaps a short int without consuming any more memory.

The preceding is all based what I learned while writing programs on my good old
Amiga, when RAM was very expensive.  Your mileage may vary, I'm pretty sure
every platform has it's own way of doing things.

Ron


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST