Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (SBGuy, AndrewAMD), 1,410 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Array with variable length #333719
07/18/10 16:33
07/18/10 16:33
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
How can I make an array with variable length? I found nothing in the manual.


Thanks for reading, thinking, answering wink
Re: Array with variable length [Re: Toryno] #333720
07/18/10 16:43
07/18/10 16:43
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
search for sys_malloc and sys_free

i think that´s what you need ^^


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Array with variable length [Re: Espér] #333760
07/18/10 21:04
07/18/10 21:04
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
I think I used a wrong word. I meant an array with dynamic length. grin This is very complicated, isn't it?


Thanks for reading, thinking, answering wink
Re: Array with variable length [Re: Toryno] #333766
07/18/10 21:25
07/18/10 21:25
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
from the manual:

sys_malloc(long size);
sys_nxalloc(long size);

Allocates a contiguous memory area with the given size. This can be used to create arrays of dynamic size. A7.79


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Array with variable length [Re: Espér] #333783
07/19/10 00:42
07/19/10 00:42
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
Yes ok, but i don't really have an idea how to use this functions for an array with dynamic size =/

I will use static sized arrays, it's not so bad.


Thanks for reading, thinking, answering wink
Re: Array with variable length [Re: Toryno] #333845
07/19/10 13:29
07/19/10 13:29
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
What do you mean with "dynamic size"? That you can enlarge the array? That can't work, as there could always be used memory right behind your array.

If you want something like a list with unlimited size, you can use linked lists.

Re: Array with variable length [Re: Lukas] #333847
07/19/10 13:50
07/19/10 13:50
Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
yes either use linked lists, or write functions to enlarge/shrink your arrays at runtime.


3333333333
Re: Array with variable length [Re: Lukas] #333848
07/19/10 13:52
07/19/10 13:52
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
Code:
//Create array
var *myarray = sys_malloc(sizeof(var)*arraylength);

//Resize array
var *temparray = sys_malloc(sizof(var)*newlength);
memcpy(temparray, myarray, sizeof(float)*arraylength);
sys_free(myarray);
myarray = temparray;

//Access array
myarray[10] = 100;



alternatively you can use malloc and realloc, but that also means that you have to free it when closing the engine.

Re: Array with variable length [Re: Slin] #333849
07/19/10 13:58
07/19/10 13:58
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i've once written a linked list which can be used as an array with variable length argument. look in the lite-c contributions thread.

Re: Array with variable length [Re: Joey] #334172
07/21/10 17:31
07/21/10 17:31
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
Thank you all, you all helped me much.


Thanks for reading, thinking, answering wink

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1