access variable through program stack


 
Thread Tools Search this Thread
Top Forums Programming access variable through program stack
# 1  
Old 11-06-2008
access variable through program stack

I am working on garbage collector in C?
How should Smilie I find the part of heap where the variable are stored. It there any compiler (GCC) support for this.
# 2  
Old 11-06-2008
Most variables in C are on the stack - anyway -- regardless,
&variable_name returns the address of the variable itself. If it is a pointer then the contents of memory at that location refer to the start of the data.

If you are messing around with heap and your program calls malloc, be careful. Most malloc implementations set aside metadata areas in heap. You mess with these and you core dump. For example Doug Lea's malloc originally had what amounts to a descriptor
for each malloc call - a pointer to the start of data storage and a 32 bit word that is length of data.
# 3  
Old 11-06-2008
GCC has a number of hooks which can be used to modify the behavior of malloc, realloc, and free by specifying appropriate hook functions. Check out __malloc_hook, __realloc_hook, etc. You can do heap consistency checking using mcheck() and probing using mprobe(). You can use the mallinfo structure to return information about the allocated memory and mallopt to tune memory allocation. However to implement garbage collection in C you are going to have to basically replace malloc and not just "modify" it. Not for the faint hearted!

There are a number of publicly available libraries which implement garbage collection generally using some variation of a mark-sweep algorithm. These libraries allow you to allocate memory as you normally would, i.e. using C malloc or C++ new, without the need to explicitly deallocate memory. One such implementation is the Boehm conservative garbage collector. Have a look at the source code to get an idea of the algorithms used. Another is the Solaris libgc library.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Local variable in a C function is not getting created in stack when its compiled with GCC

Hi, I am working in UEFI EDK2 Bios source. We created a platform related new package in the EDK2 source. I find a strange issue with the platform related code we added. When I did source level debugging I noticed the local variable in a C function is not getting created in stack when its... (6 Replies)
Discussion started by: Divya R
6 Replies

2. Programming

Access a value in 2D array in C program

Hi All, I am new to c programming. I am getting compilation error in the below program. Can somebody help me? #include<stdio.h> #include<string.h> void main() { int i=j=0; char a={'f1',4,'f2','4'}; char count; for(i=0;i<2;i++) { for(j=1;j<=2;j++) { ... (2 Replies)
Discussion started by: sam_14189
2 Replies

3. Programming

How to read max stack size -Xss that is set/default for a java program?

I need to know what is the maximum stack size i.e. -Xss my java program is running with. Is there a way to find that out from inside my java program code and outside of it. What i am looking for is to read whatever the current set max limit -Xss (stack sie) is for a particular JVM(not... (3 Replies)
Discussion started by: mohtashims
3 Replies

4. UNIX for Dummies Questions & Answers

Which program can I use for blocking unauthorized access via/ssh/ftp

Hi, I need to install a program on my Centos 5.3 server that will block unauthorized ssh/ftp access attempts. The two features I require is that I should be able to configure the program to block the IP of the intruder after a a certain amount of access attempts and that it should display a... (3 Replies)
Discussion started by: mojoman
3 Replies

5. Shell Programming and Scripting

bin program access

Hello, I was wondering if I have something in my bin dir and I want to access it from another directory to make a change how can I go about it. Thank you. (7 Replies)
Discussion started by: gingburg
7 Replies

6. Filesystems, Disks and Memory

get stack trace from C program on Solaris 8

I'm on solaris 8. I need to check the stack trace inside my C program. I don't have printstack or walkstack. I tested getcontext and it works. But how do I get the symbols from "stack_t" ? Help please. Many thanks! (4 Replies)
Discussion started by: rydahl
4 Replies

7. Programming

Accessing microsoft access from C program

I have read a number of references to libraries that could be linked into a C program to access various databases. I have been tasked with writing an oracle library that would be able to access an Microsoft access database. The oracle database is running on a Unix server and would have to access... (2 Replies)
Discussion started by: beilstwh
2 Replies

8. Programming

finding stack location in C using program

Is there a way to find the address of stack memory writing a program? Please guide me (12 Replies)
Discussion started by: jacques83
12 Replies

9. Shell Programming and Scripting

How to access the C program variables in shell script

hi I wanted to access the C program variables in shell script. This script is called from the same C program. What are the ways in which i can access variables thankx (3 Replies)
Discussion started by: bhakti
3 Replies

10. Programming

C program with Oracle database access

Hey, I want to access oracle database through Unix C programming.. Can you through me some light on that... (5 Replies)
Discussion started by: kavi
5 Replies
Login or Register to Ask a Question