* Simple question with dynamic memory allocation
@ 2009-10-19 3:54 Justin Squirek
2009-10-19 4:44 ` Gene
0 siblings, 1 reply; 2+ messages in thread
From: Justin Squirek @ 2009-10-19 3:54 UTC (permalink / raw)
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:)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Simple question with dynamic memory allocation
2009-10-19 3:54 Simple question with dynamic memory allocation Justin Squirek
@ 2009-10-19 4:44 ` Gene
0 siblings, 0 replies; 2+ messages in thread
From: Gene @ 2009-10-19 4:44 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-10-19 4:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-19 3:54 Simple question with dynamic memory allocation Justin Squirek
2009-10-19 4:44 ` Gene
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox