Oxygen Basic
Programming => Example Code => General => Topic started by: Charles Pegge 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
-
thanks charles, that I was looking for the last weeks too for converting code examples from powerbasic to oxygenbasic :)
frank
-
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?
-
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.
-
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 ::)
-
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.
-
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!
-
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.
-
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.
-
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 ;)
-
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.