[CODE] ZMemory - Dynamic Memory Allocation

Looking for Resources for your mod/project? Want to share some of your creations so others can use them? Post them here!
Post Reply
Lollipop
Zandrone
Posts: 1116
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

[CODE] ZMemory - Dynamic Memory Allocation

#1

Post by Lollipop » Fri Aug 17, 2018 1:32 pm

Combinebobnt's download button (Actually a link to the release page): https://github.com/Zelaven/ZMemory/releases

ZMemory
This thing allocates memory dynamically in ACS. Malloc and free as you might know from C or C++.
It allows you to build data structures on the fly for things like dialogue systems, menu systems or whatever else and provide an API for addons to modify these structures without having to copy-paste your script and change what it needs to be different, allowing a horizontal addon structure instead of imposing a strictly linear one. That is, different addons modifying your ACS data can do so simultaneously as long as they don't interact with conflicting semantics, but that's a semantics issue of the memory usage. which lies outside of the scope of this project to handle.

How do I do this? Global and world scope arrays can both be addressed absolutely ridiculously. I tested it with index twenty million and it works. That is the hack I have used.

There is additional information in the readme on the github page.


The current version has major version 0, so expect the API to change. I can so far reveal that the major change I have in mind for the project is to support separate world and global scope allocations, as the current version only has global scope allocation.
Spoiler: Compatibility notice (Open)
This should compatible with anything that doesn't tamper with global array 63.
As an end note: I am fully aware that the realistic use cases for something like this are rare. It's just something that I thought would be cool to make and did the bulk of the work on it in two days. I did the final little feature on it today and restructured it for proper version control. (Project started on 11 august 2018)

Download it here on the release page: https://github.com/Zelaven/ZMemory/releases
Last edited by Lollipop on Mon Aug 20, 2018 10:09 am, edited 1 time in total.

User avatar
Ivan
Addicted to Zandronum
Posts: 2200
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

Re: [SCRIPT] ZMemory - Dynamic Memory Allocation

#2

Post by Ivan » Sat Aug 18, 2018 3:24 pm

I didn't know that global variables had a large index size. That's a good find. You might want to have the "log" calls disabled for the release by the way.
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

Lollipop
Zandrone
Posts: 1116
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

Re: [SCRIPT] ZMemory - Dynamic Memory Allocation

#3

Post by Lollipop » Sat Aug 18, 2018 3:55 pm

That is a good point. It just so happens that I'm an enormous derp.
I will fix that soon. I will also try to make the first stable release as soon as possible so that it can be actively used in projects.

User avatar
jdagenet
Forum Regular
Posts: 191
Joined: Tue Jun 05, 2012 8:08 am
Clan: Cube
Clan Tag: A3
Contact:

Re: [SCRIPT] ZMemory - Dynamic Memory Allocation

#4

Post by jdagenet » Sat Aug 18, 2018 5:59 pm

This seems really useful and could save a ton of work in the long run. Nice work.
<Dynamo_>uh
<Dynamo_>did you just take the thread away
<FusedQyou>Dunno
<FusedQyou>ask the thread

Lollipop
Zandrone
Posts: 1116
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

Re: [SCRIPT] ZMemory - Dynamic Memory Allocation

#5

Post by Lollipop » Sat Aug 18, 2018 6:38 pm

Thank you. I will be very preoccupied until next weekend, but I will make the best of efforts to get the first stable version done then, at which point the API will be stable for that major release and it should be good to use.

Samuzero15tlh
Forum Regular
Posts: 219
Joined: Wed Sep 09, 2015 2:21 pm
Location: In home, sweet Home
Clan Tag: <skr>

Re: [CODE] ZMemory - Dynamic Memory Allocation

#6

Post by Samuzero15tlh » Mon Oct 14, 2019 3:28 am

Oh look!, a basic function to make dynamic lists! :D Now i need to remember how to use them on pointers...._.

Still this pice of code will help me out on the coding, thanks man!

User avatar
TDRR
Forum Regular
Posts: 106
Joined: Thu Jun 28, 2018 9:13 pm
Location: Venezuela

Re: [CODE] ZMemory - Dynamic Memory Allocation

#7

Post by TDRR » Mon Oct 14, 2019 3:14 pm

Global arrays (if they are set to the largest int, which they probably are since there's no other one-size-fits-all value) can hold 2 billion values!

Also, wouldn't it be possible to use a second global array to double the size? Once the end of the first one is reached, allocate memory on the second one. Or use all 64 global arrays to get 137438953408 values (one hundred and thirty seven billion, four hundred and thirty eight million, nine hundred and fifty three thousand, four hundred and eight) which is absolutely balls but could be really cool!
After a google search, i found out that a single array full of 0 or 1 values would be equal to... 265.4MB, and all 64 global arrays would be around 16GB O_O
That's a truckload of space for a scripting language like ACS!

What happened to this though, did it just stop or is it still in very slow development?
No Gucci, no Prada, no Supreme, but my sadness got an ending, my smile shining like bling-bling, i'm so blessed feeling like a king!

Post Reply