Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

How to get current heap pointer?

Altera_Forum
Honored Contributor II
1,513 Views

My project need to read current heap pointer, but I don't know how to implement it. 

In NiosII IDE, Variables Window, you can add a global variables for watching, 

and I find heap_end which is the one I looking for. 

but when I try to use it in my C code, the compiler report that heap_end undeclared. 

 

Anyone help? 

David
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
571 Views

Hi David_Cai, 

 

maybe heap_end is declared in the linker script? 

If you want to use symbols declared by the assembler or linker you can add an 'extern' declaration to your c code: e.g.  

 

extern int heap_end; 

 

Hope that helps, 

Wolfgang
0 Kudos
Altera_Forum
Honored Contributor II
571 Views

I have tried it, but it doesn't work... 

 

Thanks anyway... 

 

I'm confusing, I can see it in the global variables list, why I can't use it... 

 

Anyone help... 

David
0 Kudos
Altera_Forum
Honored Contributor II
571 Views

Hi David_Cai, 

 

I've looked some more at this problem. 

 

The symbol 'heap_end' is defined in nios2_60\bin\nios2-gnutools\src\newlib\libgloss\nios2\nosys_sbrk. 

It's definition is 'static char *heap_end;'  

A static symbol is only visible (for the toolchain) in the current file. If you generate an objdump listing of your executable you can see that heap_end is listed as a local symbol.  

So, if you try to reference this symbol in another file, it&#39;s the same as it wasn&#39;t defined at all. => >>undefined reference to `heap_end&#39;<< 

 

Hope this helps, 

Wolfgang
0 Kudos
Altera_Forum
Honored Contributor II
571 Views

I&#39;m very appreciated for your kindly reply... 

 

Could you kindly tell me how can you find the answer? 

 

I hope to learn fishing skill and not only fishes.http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/happy.gif  

 

Thanks again... 

David
0 Kudos
Altera_Forum
Honored Contributor II
571 Views

 

--- Quote Start ---  

originally posted by david_cai@Aug 11 2006, 07:01 AM 

could you kindly tell me how can you find the answer? 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=17538) 

--- quote end ---  

 

--- Quote End ---  

 

Hmm, let&#39;s see ... 

 

1. I created a sample project to see if I would get the same problem. 

2. I looked in the objdump file if the symbol was indeed defined (it was) 

(If you want to know anything about an elf (file format used by gcc) executable/object file look at it with objdump) 

3. I googled &#39;heap_end&#39;. a promising hit &#39;told&#39; me that heap_end was defined by the c-library. 

4. I searched the c-lib sources in my local filesystem for &#39;heap_end&#39;  

(I didn&#39;t use the explorer for that. I did use a program that searches the content of all files for &#39;heap_end&#39;). 

5. Voilá, file found => static definition. 

6. I know that static symbols are visible only in the current file. 

 

You know, experience is difficult to explain... 

Wolfgang
0 Kudos
Altera_Forum
Honored Contributor II
571 Views

Thanks very very very much...... 

Your answer is very helpful for me. 

In fact, I have done something like you, the only difference is that when I search on web , I can&#39;t get the info that heap_end is defined in c library.http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/happy.gif  

 

Thanks again for your kindly reply, 

David
0 Kudos
Reply