dtech
dtech

Reputation: 49319

c++ using 16bit pointers on 32/64 bit systems

Typically the size of a pointer is equal the "width" of the CPU, so that a pointer can typically access every system address.

Using a 16 bit pointer on a 64 bit system should allow to fit 4 16bit pointers in the same memory area as a single 64bit pointer, however a 16bit pointer only allows to address 2^16 locations.

My idea is not about saving memory, but about potential performance benefits. The idea is basically to allocate memory in chunks of 65635 and use 16 bit pointers to address those "virtual" 16bit address spaces.

Is this possible? Should I try to do it i.e. will it offer a performance benefit?

Upvotes: 2

Views: 795

Answers (2)

Jason S
Jason S

Reputation: 189836

Chances are, if you have a 32/64-bit system, it has enough RAM that the optimization benefits of your scheme would be outweighed by the complication of implementing it. You'd need to make sure it worked correctly, and your scheme would operate much slower than a direct pointer access.

Upvotes: 2

plaisthos
plaisthos

Reputation: 6322

More likely it will be a peformance hit. Modern CPU can access 32 and 64 bit data width easily. If you have 16 bit data you need need masking and so on to calculate the real address in the CPU.

A pointer for further reading is unaligned access.

Upvotes: 5

Related Questions