1

A 32 bit host Windows application setups shared memory (using memory mapped file / CreateFileMapping() API), and then other 32 bit client processes use this shared memory to communicate with each other.

I am planning to port the host application to 64 bit platform and once it is ready, I intend that both 32 bit and 64 bit client processes should be able to use the shared memory setup by the main 64 bit host application.

The original code written for host x32 application uses "size_t" almost everywhere, since this differs from 4 bytes to 8 bytes as we move from x32 to x64, I am looking for replacing it.

I intend to replace "size_t" by "unsigned long long", so that its size will be same on 32 bit & 64 bit.

Can you please suggest me better alternative? Also, will the use of "unsigned long long" have performance impact on x32 app .. i guess yes?


Research Done - Found very useful articles - a) 20 issue in porting from 32 bit to 64 bit (www.viva64.com) b) No way to restrict/change "size_t" on x64 platform to 4 bytes using compiler flags or any hooks/crooks since it is typedef

2
  • It doesn't make any sense. A 32-bit process is limited to mapping no more than 4 gigabytes into its address space. Fits a size_t without a problem. Commented Sep 23, 2012 at 21:37
  • @HansPassant: if I understand correctly, he wants to use the same code for the 32-bit and 64-bit releases, and they have to be binary compatible, so he can't use any type definitions that aren't the same on both platforms. Commented Sep 23, 2012 at 22:27

1 Answer 1

3

The use of 64-bit variables will typically slow down the 32-bit application.

However: since it typically isn't possible to locate the shared memory at the same virtual address in all of your processes, you are presumably using addresses relative to the beginning of the shared memory block; also, since your application is going to support 32-bit processes the shared memory block is presumably going to be less than 4GB in size. So why not use unsigned int?

Whatever type you choose, it would be sensible to use typedef to give it a meaningful name, e.g., shared_memory_address, and use that name consistently. That way you can change the underlying type later on if you need to.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.