From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: Elegant 'realloc'?
Date: Fri, 01 Aug 2003 00:01:54 GMT
Date: 2003-08-01T00:01:54+00:00 [thread overview]
Message-ID: <3F29ADD6.4090400@attbi.com> (raw)
In-Reply-To: slrnbihq0e.2j7.lutz@taranis.iks-jena.de
Lutz Donnerhacke wrote:
> When dealing with dynamically allocated variable length arrays, the
> allocated space might change. Is there a common idiom to simulate an
> 'realloc' (especially shrinking) other than, allocate, copy, free?
>
> declare
> procedure Free is new Unchecked_Deallocation(T_Array, T_Array_Access);
> oldp : constant T_Array_Access := current.field;
> begin
> current.field := new T_Array'(oldp(oldp'First .. current.last));
> Free(oldp);
> end;
I would just write:
declare
Current: T_Array(1..Whatever);
begin
-- process Current
end;
The array Current gets put on the stack. If you really need the array
to be extensible, containing the old value, you can either use
recursion, the heap, or Ada.Strings.Unbounded. ;-)
--
"As far as I'm concerned, war always means failure." -- Jacques Chirac,
President of France
"As far as France is concerned, you're right." -- Rush Limbaugh
prev parent reply other threads:[~2003-08-01 0:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-31 9:57 Elegant 'realloc'? Lutz Donnerhacke
2003-07-31 14:42 ` Matthew Heaney
2003-07-31 14:59 ` Lutz Donnerhacke
2003-07-31 16:50 ` Matthew Heaney
2003-07-31 16:35 ` Nick Roberts
2003-08-01 0:01 ` Robert I. Eachus [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox