Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / empty/clear array?

Author
Message
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 22nd Jan 2018 22:02
is there a command to empty or clear an array (list) immediately?

i see myArray.remove() / myArray.remove(i) but this seems to only remove one index at a time.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
puzzler2018
User Banned
Posted: 22nd Jan 2018 22:09
unless you do

length=array.length
for x=1 to length
array[x].remove()
dec length
next

Just a thought
puzzler2018
User Banned
Posted: 22nd Jan 2018 22:14
That wont work, aplogies


length=array.length
for x=1 to length
array.remove(1)
dec length
next
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Jan 2018 22:27 Edited at: 22nd Jan 2018 22:29
should be myArray.length = -1
it get complicated if you have more dimensions.
https://www.appgamekit.com/documentation/guides/12_array_changes.htm
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : AMD (17.12.1) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 22nd Jan 2018 22:29
sure you can of course iterate to remove them 1 by 1 manually, but that will be slow as tar as it will have to perform a resize operation for every index

surely there is a way to just empty it in a single operation?
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 22nd Jan 2018 22:30
Quote: "should be myArray.length = -1
it get complicated if you have more dimensions."


That'll work, thanks!
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Jan 2018 13:57
I'm curious to know if it actually frees up the memory from that array when you change its length, or if it merely flags those sectors as available and waits to overwrite them as needed?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Jan 2018 15:26 Edited at: 24th Jan 2018 15:31
Looks like it is freed. I ran a test with an array of 500k strings, checked memory use in sysinternals process explorer, reset the length and rechecked the memory, it dropped by half.

http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Jan 2018 16:39
a property change is often similar a function that is called, it resize the array so i guess it also handle the allocated memory.
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : AMD (17.12.1) Radeon R7 265 : Mac mini OS High Sierra (10.13)

Login to post a reply

Server time is: 2024-04-18 10:25:47
Your offset time is: 2024-04-18 10:25:47