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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,a1797de6fe6f5fbc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s31g2000yqs.googlegroups.com!not-for-mail From: Gene Newsgroups: comp.lang.ada Subject: Re: Simple question with dynamic memory allocation Date: Sun, 18 Oct 2009 21:44:25 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8a0368da-5bc4-4132-b885-a8d1f5db0e74@s31g2000yqs.googlegroups.com> References: <9a22eec3-925d-4551-bafe-a4c862d2413d@k33g2000yqa.googlegroups.com> NNTP-Posting-Host: 173.87.194.74 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1255927466 23195 127.0.0.1 (19 Oct 2009 04:44:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 19 Oct 2009 04:44:26 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s31g2000yqs.googlegroups.com; posting-host=173.87.194.74; posting-account=-BkjswoAAACC3NU8b6V8c50JQ2JBOs04 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8723 Date: 2009-10-18T21:44:25-07:00 List-Id: On Oct 18, 11:54=A0pm, Justin Squirek wrote: > I am working on an Ada 3d engine to render 3ds models and right now > for simplicities sake I was using a record with bounded arrays for the > model type... However, because 3ds models have multiple groups > (currently I am restricted to only rendering one per model record) and > the amount of verticies is unknown I may be wasting memory by having > the bounded arrays i.e. they are set to MAXIMUM_VERTICES instead of > just that of a loaded model's mesh's verticies. What is the best way > to dynamically allocate memory in ada? (I have seen tutorials that use > Uncheck_Deallocation and linked lists, but I would like to know if > there is an option through a preexisting ada libraries) > > > > =A0 =A0 =A0 =A0 .... > =A0 =A0 =A0 =A0 MAXIMUM_VERTICES =A0 =A0 : CONSTANT :=3D 8000; > =A0 =A0 =A0 =A0 MAXIMUM_POLYGONS =A0 =A0 : CONSTANT :=3D 8000; > =A0 =A0 =A0 =A0 MODEL_3DS_MAIN =A0 =A0 =A0 : CONSTANT :=3D 16#4D4D#; > =A0 =A0 =A0 =A0 MODEL_3DS_EDIT =A0 =A0 =A0 : CONSTANT :=3D 16#3D3D#; > =A0 =A0 =A0 =A0 MODEL_3DS_MESH =A0 =A0 =A0 : CONSTANT :=3D 16#4100#; > =A0 =A0 =A0 =A0 MODEL_3DS_NAME =A0 =A0 =A0 : CONSTANT :=3D 16#4000#; > =A0 =A0 =A0 =A0 MODEL_3DS_VERTCIES =A0 : CONSTANT :=3D 16#4110#; > =A0 =A0 =A0 =A0 MODEL_3DS_POLYGONS =A0 : CONSTANT :=3D 16#4120#; > =A0 =A0 =A0 =A0 MODEL_3DS_MAPPING =A0 =A0: CONSTANT :=3D 16#4140#; > =A0 =A0 =A0 =A0 package Float_32_Elementary_Functions > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is new Ada.Numerics.Generic_Elementary_Fu= nctions(Float_32); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 use Float_32_Elementary_Functions; > =A0 =A0 =A0 =A0 subtype Record_Vertex > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is Record_Vector_3d; > =A0 =A0 =A0 =A0 type Record_Map_Coordinate > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is record > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 U : Float_32; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 V : Float_32; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 end record; > =A0 =A0 =A0 =A0 type Record_Polygon > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is record > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 A : Integer_16_Signed; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 B : Integer_16_Signed; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 C : Integer_16_Signed; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 end record; > =A0 =A0 =A0 =A0 type Array_Record_Vertex > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is array (1..MAXIMUM_VERTICES) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of Record_Vertex; > =A0 =A0 =A0 =A0 type Array_Record_Vertex_8 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is array (1..8) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of Record_Vertex; > =A0 =A0 =A0 =A0 type Array_Record_Map_Coordinate > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is array (1..MAXIMUM_VERTICES) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of Record_Map_Coordinate; > =A0 =A0 =A0 =A0 type Array_Polygon > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is array (1..MAXIMUM_POLYGONS, 1..3) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of Integer_16_Unsigned; > =A0 =A0 =A0 =A0 type Record_Model > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is record > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 File_Name =A0 =A0 =A0: Un= bounded_String =A0 =A0 =A0 =A0 =A0 =A0:=3D To_Unbounded_String > (""); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Vertices =A0 =A0 =A0 : In= teger_16_Unsigned =A0 =A0 =A0 =A0 :=3D 0; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Polygons =A0 =A0 =A0 : In= teger_16_Unsigned =A0 =A0 =A0 =A0 :=3D 0; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Texture_Id =A0 =A0 : Inte= ger_32_Unsigned =A0 =A0 =A0 =A0 :=3D 0; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Name =A0 =A0 =A0 =A0 =A0 = : String(1..20) =A0 =A0 =A0 =A0 =A0 =A0 =A0 :=3D (others =3D> > Character'Val(0)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Polygon =A0 =A0 =A0 =A0: = Array_Polygon =A0 =A0 =A0 =A0 =A0 =A0 =A0 :=3D (others =3D> (others > =3D> 0)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Map_Coordinate : Array_Re= cord_Map_Coordinate :=3D (others =3D> (others > =3D> 0.0)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Vertex =A0 =A0 =A0 =A0 : = Array_Record_Vertex =A0 =A0 =A0 =A0 :=3D (others =3D> (others > =3D> 0.0)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Normal =A0 =A0 =A0 =A0 : = Array_Record_Vertex =A0 =A0 =A0 =A0 :=3D (others =3D> (others > =3D> 0.0)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Sphere_Vertex =A0: Array_= Record_Vertex_8 =A0 =A0 =A0 :=3D (others =3D> (others > =3D> 0.0)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Sphere_Center =A0: Record= _Vertex =A0 =A0 =A0 =A0 =A0 =A0 =A0 :=3D (others =3D> 0.0); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Sphere_Radius =A0: Float_= 32 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0:=3D 0.0; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 end record; > =A0 =A0 =A0 =A0 type Record_Model_Constant_Access > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is access constant Record_Model; > =A0 =A0 =A0 =A0 ... > <<< > > 3ds Mesh rendered with engine at current stage: > [1]http://i971.photobucket.com/albums/ae196/Justin_Sq/ada_3ds_render.jpg > > Thanks in advance for any help:) Look at the generic Ada.Containers.Vector.