Memory Leaks with pointers

T

Tricky

Guest
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?
 
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.
 

Welcome to EDABoard.com

Sponsor

Back
Top