DynArray memory allocation and use of add and set

Johan Mazel <[email protected]> Wed, 9 Jun 2010 18:09:11 +0200
Newsgroups gmane.comp.lang.ocaml.lib.devel
Message-ID <[email protected]>
Hi
I have a question about the way memory allocation is handled in the DynArray
module.
I understood the behaviour of the DynArray module as the following one, I
would like to have a confirmation that the behaviour that I'm explaining
further is the acutual one.

The DynArray module has three ways to create a new DynArray:
*create: create an empty DynArray with no elements inside.
If I do add on this DynArray, a memory space will be allocated in the
DynArray and the value to add assigned to the new element.

*make: create an empty DynArray of size specified with int parameter.
The use of add after make will simply assign the parameter in the first
previously unassigned element of the DynArray.
Any further call to add will proceed in the same manner until the allocated
space in the considered DynArray is full. At this point, a new memory space
will be allocated of the size of the type of the element to add.

*init: create a DynArray with each element assigned to a value produced by a
function applied on the indice of the element.
The use of add will simply allocate a new memory space and assign the
parameter of add as value to the new element.

I also think that the type of data stored is inferred from future
operation(s) over the DynArray. The size of memory that will be allocated
(in make for example) is deduced from the type of data stored inside the
DynArray (itself deduced from type inferring).

I am aware that these remarks also address concepts abour Ocaml itslef in
general (especially type inferring), but I think it is necessary for me to
understand them because they are linked to the understanding of the
considered API.

Thanks in advance for your help.

Johan Mazel

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo

_______________________________________________
ocaml-lib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ocaml-lib-devel