Code: Select all
+----------+------------------------------------------------------------------+
| area 1 | free area |
+----------+------------------------------------------------------------------+
+-----------+----------+------------------------------------------------------+
| area 1 | area 2 | free area |
+-----------+----------+------------------------------------------------------+
+-----------+----------+----------+-------------------------------------------+
| area 1 | area 2 | area 3 | free area |
+-----------+----------+----------+-------------------------------------------+
My questions:
Should I skip a few bytes between areas so the NEXT area is aligned? How should I align it; to a multiple of 2 bytes or 4 bytes or what? I want these structures to be accessed efficiently over a wide range of processors to keep it portable. How about pointers? Should they be aligned to (sizeof)whatever*? Or perhaps (sizeof)whatever* / 2 ?
Background information:
As my program initializes, it needs to allocate a large number of areas. They are never freed until none of them are needed any more, at which point they are ALL freed in mass. I've been using malloc() for each individual area up to now, but malloc() leaves big holes in the allocated storage and adds extra bytes for storage accounting (for use by free) but if I don't need that flexibility, I just want to jam the areas right up next to each other. I am aware that various processors handle unaligned variables differently, but as I said, I want it to run efficiently with a wide assortment of processors.
Caitlin