Author Topic: REDIM  (Read 3851 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
REDIM
« on: April 19, 2013, 06:01:50 AM »

This is a set of macros for handling dynamic arrays. It will be found in examples/constructs

When you have finished with a dynamic array, redimensioning it to 0 elements will release its memory space.


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

macro DynRedim(v,n)
===================
  scope
  sys p=@v
  sys le
  indexbase 0
  if p
    le=0xffffffff and *(p-4) 'length of original
  end if
  @v=getmemory n*sizeof v 'new mem block
  if (le>n*sizeof v)
    le=n*sizeof v         'clip data length to fit
  end if
  if le
    copy @v,p,le          'copy data
  end if
  freememory p            'free original
  end scope
end macro

macro DynSize(v)
================
(0xffffffff and *(@v-4))
end macro


macro DynCount(v)
================
((0xffffffff and *(@v-4))/ sizeof v)
end macro



'TEST: DYNAMIC 2 DIMENSIONAL ARRAY
'=================================


indexbase 0

sys nx=100,ny=50 'array size

DynDim double,d,nx*ny

'accessing array in 2 dimensions

macro da(x,y)
=============
 d(x+y*nx)
end macro


da(50,10)=123.125
DynRedim d, nx*ny*2
print da(50,10)   'data is preserved
print DynSize  d  'size of array in bytes
print DynCount d  'total number of elements


'Release Array Space

DynRedim d, 0


Charles



Frankolinox

  • Guest
Re: REDIM
« Reply #1 on: April 19, 2013, 08:57:49 AM »
thanks charles, that I was looking for the last weeks too for converting code examples from powerbasic to oxygenbasic :)

frank

Aurel

  • Guest
Re: REDIM
« Reply #2 on: April 19, 2013, 10:38:50 AM »
Thanks Charles ;)
Do you can explain to us what is main advantage of this aproach using macros
vs Built in REDIM ?
if is no problem of course...

And do you think that if you built-in REDIM directly in oxygen cose some troubles maybe?

Charles Pegge

  • Guest
Re: REDIM
« Reply #3 on: April 29, 2013, 03:16:47 AM »
Hi Aurel,

I'm applying the principle of minimalism to the Oxygen core. Only essential constructs are built-in then the rest can go into source-code libraries.

Aurel

  • Guest
Re: REDIM
« Reply #4 on: April 29, 2013, 03:48:42 AM »
Ok Charles i agree with you about that and i don't use it to much
because in EBasic dont have REDIM to.
However i would like to see implemented LinkedList,Hash...
For example EBasic and PureBasic have built in LinkedList and HashTable and work very well
in this languages.

By the way i cannot found your example about LinkedList anywhere  ::)

Charles Pegge

  • Guest
Re: REDIM
« Reply #5 on: April 29, 2013, 04:29:21 AM »
There is a Hash name-and-token storage example in projectsA/ProgLang.

Linked lists come in all shapes and sizes, but they have been found to perform less efficiently than simple lists, even allowing for insertion and deletion of list members. This is because processor caches work best with contiguous memory blocks. So you may be better off without them.

Peter

  • Guest
Re: REDIM
« Reply #6 on: April 29, 2013, 04:48:47 AM »
HASH TABLE, LINKEDLIST..

I ask me how many people who own  OxygenBasic, use HASH TABLES?
I mean, we have 39 member and two active.

Special wishes: always only  for one man.
No wonder that every DLL is a chaos.  :D

Don't put everything in your DLL!   

Aurel

  • Guest
Re: REDIM
« Reply #7 on: April 29, 2013, 05:25:12 AM »
I know that this containers are not much used and like Peter says we have 2 or 4 active members.
BUT how then this things work in some other compilers without problems  ???
And i just ask about them I don't need them right now.

Haim

  • Guest
Re: REDIM
« Reply #8 on: April 29, 2013, 10:10:24 PM »
Hi,
For what it's worth, I think that hash tables and linked list are quite useful.
Having them built in would be very nice to have.

Aurel

  • Guest
Re: REDIM
« Reply #9 on: April 30, 2013, 02:46:31 AM »
Quote
For what it's worth, I think that hash tables and linked list are quite useful.
Having them built in would be very nice to have.

So this is not just me, and i really don't want to force Charles that he do something
just for me .
I have study all examples from oxygen pack and i can say that 50% of them are just
for exemple how some thing work...which is ok for me ...but for people who have in plan
(maybe) to use oxygen is not very much usefull.
Maybe is this just my opinion...so don't get me wrong ;)

Charles Pegge

  • Guest
Re: REDIM
« Reply #10 on: April 30, 2013, 04:14:24 AM »
There are many useful functions which could be included in a second layer. If these were automatically  inserted by the compiler, then you would not need to include them explicitly, neither would the Oxygen core dll have to carry them. They would appear to the programmer as a natural extension to the language.