this can reduce memory usage - slightly - but it will not improve speed, since you will have to move your short pointer to an absolute pointer, and this will add overhead, and you will lose most of the benefits of type checking.
It will look something like this:
typedef unsigned short ptr;
...
char* offset = malloc(256);
ptr var1 = 0, var2 = 4, var3 = 8;
*((int*) &offset[var1]) = ((int) 1) << 16;
printf("%i", *((int*) &offset[var1]));
with even more tricks, you can come up with your own brk () to help allocate memory from the offset.
Is it worth it? IMO no.
source
share