C/memory map
Expert: Prince M. Premnath - 2/20/2008
Questionin interview, i have been asked for " can you draw a memory map for c".what is memory map?
AnswerHi Dear G.Kalai !
Answer for this question depends on the operating system and the compiler !
For our discussion let me assume that you are using DOS based TURBO C 3.0 Compiler , This compiler supports 5 different types of memory model to hold both code and data that has been used by the program
A data segment is one of the sections of a program in an object file or in memory, which contains the global variables that are initialized by the programmer.
The Data part contains constants used by the program that are not initialized to zero. For instance the string defined by char s[] = "hello world"; would exist in the Data.
The Heap area begins at the end of the Data segment and grows to larger addresses from there. The Heap area is managed by malloc, realloc, and free, which use the brk and sbrk system calls to adjust its size. The Heap area is shared by all shared libraries and dynamic load modules in a process.
Let me summarize the memory models !
Segment Pointers
Memory model Code Data stack Code data
Tiny Total of 64k mem near near
Small 64k | 64K near near
Medium 1MB | 65K far near
Compact 64K | 1MB near far
Large 1MB | 1MB far far
Huge 1MB |64K |64K far far
So based on the memory model you are given various options to use the main memory for your program depend on the requirements !
Note : This restriction is relaxed if its a window based compiler , i recommend you to refer the reference manual of the compiler vendor's
Thanks and Regards!
Prince M. Premnath