Memory Leaks with pointers

This is a discussion on Memory Leaks with pointers within the vhdl forums in Programming Languages category; Consider the following: type a_t; type a_t_ptr is access a_t; type b_t; type b_t_ptr is access b_t; type a_t is array(integer range <>) of integer; type b_t is array(integer range <>) of a_t_ptr; begin process variable P : b_t_ptr; begin P := new b_t(1 to 10); for i in 1 to 10 loop p(i) = new a_t(1 to 10); end loop; DEALLOCATE(P); wait; end process; have I just caused a memory leak by not deallocating all the elements in the top level array? would you have to quit the simulator to free it again, or just end the simulation?...

Go Back   Application Development Forum > Programming Languages > vhdl

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-05-2008, 12:24 PM
Tricky
Guest
 
Default Memory Leaks with pointers

Consider the following:
type a_t;
type a_t_ptr is access a_t;

type b_t;
type b_t_ptr is access b_t;

type a_t is array(integer range <>) of integer;
type b_t is array(integer range <>) of a_t_ptr;

begin

process
variable P : b_t_ptr;
begin

P := new b_t(1 to 10);

for i in 1 to 10 loop
p(i) = new a_t(1 to 10);
end loop;

DEALLOCATE(P);
wait;
end process;

have I just caused a memory leak by not deallocating all the elements
in the top level array? would you have to quit the simulator to free
it again, or just end the simulation?
Reply With Quote
  #2  
Old 08-05-2008, 12:40 PM
Jonathan Bromley
Guest
 
Default Re: Memory Leaks with pointers

On Tue, 5 Aug 2008 09:24:00 -0700 (PDT),
Tricky wrote:

>Consider the following:
> type a_t;
> type a_t_ptr is access a_t;
>
> type b_t;
> type b_t_ptr is access b_t;
>
> type a_t is array(integer range <>) of integer;
> type b_t is array(integer range <>) of a_t_ptr;
>
>begin
>
> process
> variable P : b_t_ptr;
> begin
>
> P := new b_t(1 to 10);
>
> for i in 1 to 10 loop
> p(i) = new a_t(1 to 10);
> end loop;
>
> DEALLOCATE(P);
> wait;
> end process;
>
>have I just caused a memory leak by not deallocating all the elements
>in the top level array?


I believe so.

> would you have to quit the simulator to free
> it again, or just end the simulation?


Depends on the simulator, I guess. Simulators do so much
fooling around with memory allocation anyways that I've never
found a way to detect that sort of thing reliably. Whenever
I build hierarchical dynamically-allocated structures, I
always provide them with a delete() method that deletes
all their component objects before deallocating the
top level object. Maybe that's just over-paranoid,
but I've survived to this old age mainly by being
paranoid and I don't plan on changing now :-)
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:13 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.