[DGD]Dynamic Array of Objects ?

Par Winzell zell at skotos.net
Wed Feb 21 00:01:17 CET 2001


> lpc arrays are always dynamic. and you can do stuff like
> insert_your_basic_array_variable_here+=({ stuff }) ;
> they never need to be initailized with a certain size in mind, you can do
> that if you feel like it though with the
> allocate kfun, though i personally have never had to use it.

It is mostly an efficiency concern.

mixed *copy(mixed *arr) {
  mixed *res;
  int i;

  res = ({ });
  for (i = 0; i < sizeof(arr); i ++) {
   res += arr[i .. i];
  }
  return res;
}

is an O(N^2) process (internally) while

mixed *copy(mixed *arr) {
  mixed *res;
  int i;

  res = allocate(sizeof(arr));
  for (i = 0; i < sizeof(arr); i ++) {
    res[i] = arr[i];
  }
  return res;
}

is linear in N.

I'm hoping that some future version of DGD may be able to do some 
internal optimization to render the earlier version O(N) as well (by 
wasting some memory internally and keeping head/tail buffers for arrays 
so they do not need to be constantly reallocated upon array addition).

Zell


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list