Author Topic: Next Version  (Read 2446 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Next Version
« on: April 16, 2012, 03:36:23 AM »
Deleted
« Last Edit: May 07, 2015, 11:23:11 AM by Peter »

Charles Pegge

  • Guest
Re: Next Version
« Reply #1 on: April 16, 2012, 07:18:34 AM »

Do you mean dynamic arrays Peter?

Charles Pegge

  • Guest
Re: Next Version
« Reply #2 on: April 16, 2012, 08:19:07 AM »
Try this:

Code: [Select]
indexbase 0


macro DynamicArray(t,v,n) t*v : @v=getmemory n*sizeof t

sys nx=100,ny=50

dynamicArray single,d,nx*ny
macro da(x,y) d(x+y*nx)


da(50,10)=123
print da(50,10)

freememory @d


Charles

Charles Pegge

  • Guest
Re: Next Version
« Reply #3 on: April 16, 2012, 09:39:32 AM »

Dynamic arrays are complicated, but the macros can be held in a library.

Code: [Select]

macro DynamicArray(t,v,n)
  t*v
  @v=getmemory n*sizeof t
end macro

macro DynamicRedim(t,v,n)
  scope (
  sys p=@v
  indexbase 0
  sys le=*p[-1]           'length of original
  @v=getmemory n*sizeof t 'new mem block
  if le>n*sizeof t
    le=n*sizeof t         'clip data length to fit
  end if
  if le
    copy @v,p,le          'copy data
  end if
  freememory p
  )
end macro


'================

indexbase 0

sys nx=100,ny=50

DynamicArray double,d,nx*ny
macro da(x,y) d(x+y*nx)


da(50,10)=123
DynamicRedim double, d, nx*ny*2
print da(50,10)


'freememory @d
DynamicRedim double, d, 0 'void array

Charles