Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to know memory allocation for pointers when the machine is 64 bit and OS in 32 bit.For Example when the machine as well as the OS are 32 bit the pointer has 4 bytes and for 64 bit 8 bytes.If we use 64 bit machine keeping the OS as 32 bit then what will happen to the pointer size??and how it is managed by OS with 64 bit hardware???????
Posted
Comments
mbue 24-Aug-11 7:45am    
Once upon a time we had: near, far and huge pointers. Im afraid i dont understand your question. Let do it the processor and the virtual address mapping these things for you.
Regards.

// If we use 64 bit machine keeping the OS as 32 bit
// then what will happen to the pointer size??

Just compile the following:
C++
//..
int* pInt(NULL);
cout << sizeof(pInt);
//..
...and let it answer :)

// how it is managed by OS with 64 bit hardware???????

A 64-processor can go the both ways.

Probably like a browsing donkey
fixed by a 32- or 64-meters cord... :)
 
Share this answer
 
Comments
LaxmikantYadav 24-Aug-11 3:17am    
Hi Eugen can you please explain how the memory management done in second case. ( For eg. generally 64 bit os with 64 bit manchine allocate 8 bytes for pointer and if OS is 32 bit with 64 bit it allocate 4 bytes so how the remaning 4 bytes are use by OS? )
Eugen Podsypalnikov 24-Aug-11 3:37am    
Hi Laxmikant Yadav,
the remaining bytes (in the processor registers) are not using in the second case.
This behavior (machine code) is the result of a (32- or 64-bit) compiler and its appropriate linker.
So a 64-processor can receive the 32- or 64-bit instructions (commands).
A processor is a HW part.
An OS or an executable file are SW.
The SW can be build by 32- or 64-compiler/linker.
It is also possible to provide (send) 32-bit instructions of an executable by a 64-bit OS on (to) a 64-bit processor. This process (of that executable) will take just a "shorter cord" for its (memory) space addressing :)
A 32 bit OS can not work with memory beyond the space adressable by 32 bits. That's what '32 bit OS' means! It's a restriction of address space. An OS might even be more restrictive as it might reserve certain parts of the address space for internal use. E. g. Windows reserves about 500MB-1GB of the address space this way, meaning you can at most use 3-3.5 GB on a 32 bit OS even though it might have 4 GB memory available.

Most compilers define pointer size depending on the target OS, but not all. This is compiler dependend, not OS dependend! So, while many compilers may use only 4 bytes in a program targeted at a 32 bit OS, some might use 8 or even 16 bytes.

Normally you shouldn't need to care about your actual hardware system - that is what the compiler does for you. The only thing you may occasionally need to watch out for is the size needed to store a pointer, and you can query that at runtime (or even at compile time, using templates) with the help of the sizeof operator.
 
Share this answer
 
Hi,

First of all the compiler decides the memory allocation for the datatypes depending on the target compiler.
For example in turbo c compiler(16 bit) the pointer takes up 16 bytes,and in a 32 bit compiler like visual c++ it will be 32 bits and 64 bit compilers are also available to work in 64 bit machine.
This link shows how to use visual c++ compiler in 64 bit environment :http://www.viva64.com/en/k/0006/

The terms 32-bit and 64-bit refer to the the size of the computers processor's registers,that are used for various functions like instruction fetching and execution,more the number of bits they can hold,faster the processing.
 
Share this answer
 
Comments
Member 8520689 27-Dec-11 12:05pm    
code to create a memory management system using c lanaguage
Ive found an interesting article about that:
Licensed Memory in 32-Bit Windows Vista
Regards.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900