Provides 32bit -> 16bit pointer compression. More...
Provides 32bit -> 16bit pointer compression.
On many platforms, some pointers may have to be aligned, e.g., to 4 byte boundaries. On 32bit platforms, that makes it possible to store all possible aligned 32bit pointers in a 16bit value as long as the total memory is small (e.g., with 4 byte alignment, all pointers within 256kb RAM can be represented by a 16bit value). This can save memory, at the cost of some instructions for compression/decompression.
In order to use pointer compression, ZPTR_BASE needs to be defined to a (4 byte aligned) base address.
A printf format macro (PRIzptr) is provided.
You can then use zptr_t instead of a pointer type, using the supplied functions to compress / decompress, e.g.,
void func(void *ptr) {
printf("%"PRIzptr"\n", ptr);
...
free(ptr);
}
... would become
void func(zptr_t zptr);
printf("%"PRIzptr"\n", zptr);
...
free(zptrd(zptr));
}
If ZPTR_BASE is unset, zptr_t / zptrc() / zptrd() will transparently and without overhead compile to normal (uncompressed) pointer operations.
Files | |
| file | zptr.h |
| 32bit -> 16bit pointer compression implementation | |
Macros | |
| #define | PRIzptr PRIu16 |
| zptr printf format definition | |
| #define | ZPTR_MAX_ADDR ((uintptr_t)ZPTR_BASE + (1 << 18)) |
| zptr highest compressible address | |
Typedefs | |
| typedef uint16_t | zptr_t |
| zptr type definition | |
Functions | |
| static int | zptr_check (void *pointer) |
| Determine if a pointer is compressible by zptrc() More... | |
| static zptr_t | zptrc (void *pointer) |
| Compress a pointer (if possible) More... | |
| static void * | zptrd (zptr_t zptr) |
| Decompress a pointer. More... | |
|
inlinestatic |
|
inlinestatic |