From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.98.91.7 with SMTP id p7mr3024337pfb.10.1461095313653; Tue, 19 Apr 2016 12:48:33 -0700 (PDT) X-Received: by 10.182.102.73 with SMTP id fm9mr57232obb.9.1461095313612; Tue, 19 Apr 2016 12:48:33 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!gy3no6397959igb.0!news-out.google.com!u9ni97igk.0!nntp.google.com!g8no4459796igr.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 19 Apr 2016 12:48:33 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=75.161.65.33; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 75.161.65.33 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0d653ce4-c8da-4bf8-8ef4-94693c158447@googlegroups.com> Subject: Re: problems parse (large) json file with gnatcoll.json From: Shark8 Injection-Date: Tue, 19 Apr 2016 19:48:33 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:30199 Date: 2016-04-19T12:48:33-07:00 List-Id: On Monday, April 18, 2016 at 1:12:49 PM UTC-6, bj=F6rn lundin wrote: >=20 > The loading function now looks like >=20 > function Load_File(Filename : in String) return String is > use Ada.Directories; > File_Size : constant Natural :=3D Natural (Size (Filename)); > subtype JSON_String is String (1 .. File_Size); > type String_Ptr is access JSON_String; > Content : constant String_Ptr :=3D new JSON_String; > package File_IO is new Ada.Direct_IO(JSON_String); > File : File_IO.File_Type; > begin > File_IO.Open (File =3D> File, Mode =3D> File_IO.In_File, > Name =3D> Filename); > File_IO.Read (File =3D> File, Item =3D> Content.all); > File_IO.Close(File =3D> File); > return Content.all; > end Load_File; > -------------------------- Just replace the return w/ an extended return containing an instance of Unc= hecked_Deallocation; eg: return Result : JSON_String :=3D 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 sco= pe all instances should become invalid, thus allowing the compiler to recla= im it's memory from the storage pool.