Variable storage locations ...


 
Thread Tools Search this Thread
Top Forums Programming Variable storage locations ...
# 1  
Old 05-06-2010
Variable storage locations ...

I've got the following two queries:

1) What's the difference in performance if a variable storage is at bss and not at the data section (apart from the initialization to zero in case of data section variables --like static variables).

In general, why a developer need to bother about the storage location of a variable which is on the bss section?

2) Does the ELF format has such memory sections / layout (Stack, bss, dataSection, rodata, heap) of any program? Is that hardware supported?

I'm looking ahead to have a good general discussion on process memory layout, please?

Thanks in advance.
# 2  
Old 05-06-2010
Quote:
Originally Posted by Praveen_218
I've got the following two queries:

1) What's the difference in performance if a variable storage is at bss and not at the data section (apart from the initialization to zero in case of data section variables --like static variables).
As far as the hardware's concerned, memory is memory. The bss segment isn't special.
Quote:
In general, why a developer need to bother about the storage location of a variable which is on the bss section?
Generally, they wouldn't care what segment it was in unless they were programming in raw assembly. C programmers don't deal with segments, just variable scope. Global or static variables would end up in bss.
Quote:
2) Does the ELF format has such memory sections / layout (Stack, bss, dataSection, rodata, heap) of any program? Is that hardware supported?
The ELF format tells the kernel what memory segments a program expects where, what can be relocated, any shared libraries that need mapping, etc, etc. It's quite complex. The ELF format itself isn't hardware-supported, since it's the kernel's job to manage memory, but virtual memory itself is supported in hardware on most any modern platform and OS.
Quote:
I'm looking ahead to have a good general discussion on process memory layout, please?
Process memory layout is all virtual these days. The kernel keeps a table of what memory addresses a process is allowed to use and what physical memory(if any) they are associated with. Each process' memory is independent* The processor of course supports this table in hardware, otherwise all memory operations would be painfully slow!

The binary code in an ordinary executable, as well as things like its stack, are by tradition loaded/created in consistent locations. Shared libraries on the other hand are generally relocatable.

If you're interested in memory segments, you may find A Whirlwind Tutorial on Creating Really Teensy ELF Executables enlightening, it goes right to the heart of segments and ELF itself.

* Oversimplification, but mostly true as far as the programmer's concerned
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable storage using awk

Hi, there is a file which contains some values in column format. I want to store those values in a variable.but when i am using awk it is storing all the values at a time. x=`awk '{print $1}' test2.txt` echo $x ab cd mn jk yt but i want the values to be stored one by one in that variable.... (3 Replies)
Discussion started by: arijitsaha
3 Replies

2. Programming

Synchronization Variable Storage

We know that all the threads in process share the process address space. We have various synchronization mechanisms like semaphore, mutex, spinlock, critical sections etc . used for thread syncronization. I want to know in which part of the process address space are these synchronization... (2 Replies)
Discussion started by: rupeshkp728
2 Replies

3. Programming

static variable storage

Hi, Where are the static variables actually stored in memory. Is it in .bss? In that case how is its storage different from global variables? From the ELF data is it possible to see the storage of different variables used in the program? eg: static int temp1; int gtemp1; main() {... (1 Reply)
Discussion started by: naan
1 Replies
Login or Register to Ask a Question