comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: problems parse (large) json file with gnatcoll.json
Date: Tue, 19 Apr 2016 12:48:33 -0700 (PDT)
Date: 2016-04-19T12:48:33-07:00	[thread overview]
Message-ID: <0d653ce4-c8da-4bf8-8ef4-94693c158447@googlegroups.com> (raw)
In-Reply-To: <nf3bd5$t6m$1@dont-email.me>

On Monday, April 18, 2016 at 1:12:49 PM UTC-6, björn lundin wrote:
> 
> The loading function now looks like
> 
>   function Load_File(Filename : in String) return String is
>      use Ada.Directories;
>      File_Size    : constant Natural := Natural (Size (Filename));
>      subtype JSON_String is String (1 .. File_Size);
>      type String_Ptr is access JSON_String;
>      Content : constant String_Ptr := new JSON_String;
>      package File_IO is new Ada.Direct_IO(JSON_String);
>      File : File_IO.File_Type;
>   begin
>      File_IO.Open (File => File, Mode => File_IO.In_File,
>                    Name => Filename);
>      File_IO.Read (File => File, Item => Content.all);
>      File_IO.Close(File => File);
>      return Content.all;
>   end Load_File;
>   --------------------------

Just replace the return w/ an extended return containing an instance of Unchecked_Deallocation; eg:

return Result : JSON_String := Content.all do
  Free( Content ); -- "Free" is the instantiation of Unchecked_Deallocation.
end return;

*BUT*

You really shouldn't need it, IIRC when the type String_Ptr goes out of scope all instances should become invalid, thus allowing the compiler to reclaim it's memory from the storage pool.


  reply	other threads:[~2016-04-19 19:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-18 18:21 problems parse (large) json file with gnatcoll.json Björn Lundin
2016-04-18 18:51 ` Jeffrey R. Carter
2016-04-18 19:05   ` Björn Lundin
2016-04-19 19:48     ` Shark8 [this message]
2016-04-20  7:50       ` AdaMagica
2016-04-21  8:44       ` Björn Lundin
2016-04-25 10:38     ` briot.emmanuel
2016-04-25 15:12       ` Björn Lundin
2016-04-18 18:59 ` joakimds
2016-04-18 19:23   ` Björn Lundin
2016-04-19  8:17 ` Jacob Sparre Andersen
2016-04-19  9:14   ` Björn Lundin
2016-04-19  9:56 ` gautier_niouzes
2016-04-19 12:49   ` G.B.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox