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.

DarkBASIC Professional Discussion / how to increase the "stack size" of a compiled darkbasic pro program?

Author
Message
Alex Ogheri
2
Years of Service
User Offline
Joined: 19th Dec 2021
Location:
Posted: 19th Dec 2021 11:38
Hi,

dont know if it is possible

but does some of you experts know how to increase the stack size of a darkbasic pro program ? (particularly for hungrily recursive programs ? )

ciao and thx !!
Alex
Bored of the Rings
User Banned
Posted: 20th Dec 2021 03:52
well it can't be done in editor. you need to download the dbpro open source on github and update/compile with VS.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 20th Dec 2021 12:12 Edited at: 20th Dec 2021 12:12
When I get a moment I'll have a look shouldn't be too hard.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Nomad Soul
Moderator
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location: United Kingdom
Posted: 22nd Dec 2021 17:51
what will increasing the stack size achieve?
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 24th Feb 2022 05:14

Quote: "what will increasing the stack size achieve?"


just think of the stack it as a the bucket of memory your program uses to store local data such as variables / arrays / types on. When you enter a different scope, (call a function) the local data within the function it put on top of the stack, then the locals are accessed from this new base location. This is normally fine as you never really need loads of locals & globals, until you try and use recursions for example. Recursion is when a function calls itself, each time the new call leaves bread crumbs on the stack and if your not careful you can overflow the stack. You can solve such issues by increasing the stack size yeah, or by converting a recursive function to use heaps. The latter makes a lot more sense IMHO.

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Bored of the Rings
User Banned
Posted: 24th Feb 2022 06:28
yes there are pros and cons, stack memory is considered safer and uses less space. I use recursion quite a lot these days inside and outside work. so heap is best with recursion as I want to retain the data in the variable, and I use stack when I no longer need the variable.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 24th Feb 2022 21:39
I don't want to derail the conversation but this seems oddly related, it's probably right on topic actually.

I posted about "Batch Reads/Writes" being 50x faster than regular reading and writing.
https://forum.thegamecreators.com/thread/227755

In order to do this, the system has to create a huge array with each byte that is going to be written to file. This worked fantastically until I tried to use it on a file that was 10kb. Then I got an error I never saw before. Paraphrasing "There is not enough memory to create an array of this size."

I was retrofitting an existing program that was saving and loading a database, hoping to get a nice 50x load/save boost. However as soon as that happened I stopped and moved on. It's possible there was a bug somewhere that made the array much much larger than intended (like saving a string but the loop goes out of control and you try to save millions of characters until it crashes). However if not, then it will be really difficult to make this work for anything more than tiny files.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Feb 2022 02:17

Quote: " In order to do this, the system has to create a huge array with each byte that is going to be written to file. This worked fantastically until I tried to use it on a file that was 10kb. Then I got an error I never saw before. Paraphrasing "There is not enough memory to create an array of this size." "


Arrays are dynamic allocations held in general purpose memory in DBpro, so you've most likely hit upon the 32bit limitations without really noticing it. One common issue can occur with multiple dimension arrays.

imagine a 1D array of 32 bit integers, that's (2^32)/4 (unsigned) index range for a flat contiguous allocation of memory.

but what if we wanted a 2D integer array ? It doesn't take long before the combined 2D ordinates will overflow the 32bit range. ($10000*$10000) Since the data underneath is still just one contiguous chunk.

Types & Strings further compound things, since each is separate allocation.











PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 25th Feb 2022 18:10
I did some extra checking and it file was 10mb not 10kb. The code was crashing after making an integer array of about 50 million index size. It was actually making much more but I narrowed the limit down somewhat. Similar sized memblock is in memory likely also adding to the issue.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!

Login to post a reply

Server time is: 2024-04-26 07:11:17
Your offset time is: 2024-04-26 07:11:17