comp.lang.ada
 help / color / mirror / Atom feed
From: Gene <gene.ressler@gmail.com>
Subject: Re: Simple question with dynamic memory allocation
Date: Sun, 18 Oct 2009 21:44:25 -0700 (PDT)
Date: 2009-10-18T21:44:25-07:00	[thread overview]
Message-ID: <8a0368da-5bc4-4132-b885-a8d1f5db0e74@s31g2000yqs.googlegroups.com> (raw)
In-Reply-To: 9a22eec3-925d-4551-bafe-a4c862d2413d@k33g2000yqa.googlegroups.com

On Oct 18, 11:54 pm, Justin Squirek <justin.squi...@gmail.com> 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)
>
>
>
>         ....
>         MAXIMUM_VERTICES     : CONSTANT := 8000;
>         MAXIMUM_POLYGONS     : CONSTANT := 8000;
>         MODEL_3DS_MAIN       : CONSTANT := 16#4D4D#;
>         MODEL_3DS_EDIT       : CONSTANT := 16#3D3D#;
>         MODEL_3DS_MESH       : CONSTANT := 16#4100#;
>         MODEL_3DS_NAME       : CONSTANT := 16#4000#;
>         MODEL_3DS_VERTCIES   : CONSTANT := 16#4110#;
>         MODEL_3DS_POLYGONS   : CONSTANT := 16#4120#;
>         MODEL_3DS_MAPPING    : CONSTANT := 16#4140#;
>         package Float_32_Elementary_Functions
>                 is new Ada.Numerics.Generic_Elementary_Functions(Float_32);
>                 use Float_32_Elementary_Functions;
>         subtype Record_Vertex
>                 is Record_Vector_3d;
>         type Record_Map_Coordinate
>                 is record
>                         U : Float_32;
>                         V : Float_32;
>                 end record;
>         type Record_Polygon
>                 is record
>                         A : Integer_16_Signed;
>                         B : Integer_16_Signed;
>                         C : Integer_16_Signed;
>                 end record;
>         type Array_Record_Vertex
>                 is array (1..MAXIMUM_VERTICES)
>                 of Record_Vertex;
>         type Array_Record_Vertex_8
>                 is array (1..8)
>                 of Record_Vertex;
>         type Array_Record_Map_Coordinate
>                 is array (1..MAXIMUM_VERTICES)
>                 of Record_Map_Coordinate;
>         type Array_Polygon
>                 is array (1..MAXIMUM_POLYGONS, 1..3)
>                 of Integer_16_Unsigned;
>         type Record_Model
>                 is record
>                         File_Name      : Unbounded_String            := To_Unbounded_String
> ("");
>                         Vertices       : Integer_16_Unsigned         := 0;
>                         Polygons       : Integer_16_Unsigned         := 0;
>                         Texture_Id     : Integer_32_Unsigned         := 0;
>                         Name           : String(1..20)               := (others =>
> Character'Val(0));
>                         Polygon        : Array_Polygon               := (others => (others
> => 0));
>                         Map_Coordinate : Array_Record_Map_Coordinate := (others => (others
> => 0.0));
>                         Vertex         : Array_Record_Vertex         := (others => (others
> => 0.0));
>                         Normal         : Array_Record_Vertex         := (others => (others
> => 0.0));
>                         Sphere_Vertex  : Array_Record_Vertex_8       := (others => (others
> => 0.0));
>                         Sphere_Center  : Record_Vertex               := (others => 0.0);
>                         Sphere_Radius  : Float_32                    := 0.0;
>                 end record;
>         type Record_Model_Constant_Access
>                 is access constant Record_Model;
>         ...
> <<<
>
> 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.



      reply	other threads:[~2009-10-19  4:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-19  3:54 Simple question with dynamic memory allocation Justin Squirek
2009-10-19  4:44 ` Gene [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