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 / memory management

Author
Message
ryansobol
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 1st Jul 2003 18:20
What kind of automatic garbage collection, or memory deallocation, does dbpro do? What kinds of 'objects' must a programmer deallocate before ending a program? Im not a big fan of memory leaks and crashing the OS.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st Jul 2003 20:15
technically non ... however if you use a portion of memory like

result=make memory(1024)

then you have to delete that after exiting because dbp won't do it for you, but thats the only instance which isn't automatically released.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Jul 2003 20:22
I'm not sure that even that's true. Allocated memory for a dead process is automatically collected back by the OS.

Memory is generally only lost when a process crashes - and that's due to DLLs and COM interfaces not having their reference counts decreased and being unloaded at zero, not memory leaks.

Generally, I don't think that you have to worry about it
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st Jul 2003 20:24
well the manual mentions that the make memory & pointers generally have to be used with care and cleared manually.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Jul 2003 20:32
Absolutely. Careful memory management is a must during the running of your program.
ryansobol
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 1st Jul 2003 21:50
so if an app loads a sound file or a model or a bsp map, then you dont need to worry about unloading the resource? how about user-defined variables and arrays? will dbpro automatically deallocate everything once the app terminates?

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 1st Jul 2003 22:05
should do

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 1st Jul 2003 23:55
But you never know...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
ryansobol
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 2nd Jul 2003 00:06
LOL, MrTAToad. Well, lets hope not. Basically i didnt know if there was any commands that unloaded resources that get loaded into memory. Well, sounds like there arent. Thanx all, youve been a big help!

PS- im find it interesting that DBPRO has pointers. could anyone refer me to a good tutorial or code snipet that shows the syntax?

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 2nd Jul 2003 01:11
The syntax for pointer operation is :

*ptr=1024

You've only got limited control over ptr, hence the reason IanM and myself did the peek/poke commands.

There aren't any commands to unload all resources, aside from the usual delete commands, which you should use. However, we dont know whether this releases ALL used memory...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
ryansobol
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 2nd Jul 2003 02:21
Quote: "There aren't any commands to unload all resources, aside from the usual delete commands, which you should use."


Could u give me an example? I didnt see the delete command in the DBPRO manual.

Quote: "You've only got limited control over ptr, hence the reason IanM and myself did the peek/poke commands."


What sort of control do you have? Pointer addition and subtraction? Are the peek/poke commands in a dll that I could download?

Im full of questions today.

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 2nd Jul 2003 02:48
make object cube 1,10.0
delete object 1

stuff like that... its good practise to make sure you clean anything you create on exit - generally most of the more experienced guys and gals here do but thats probably more cause they have C/C++ backgrounds where you have to.

the pointer dll is on toads website to download for free, with examples



think thats a pretty good example of the pointers
they're pretty basic but i'm sure it'll be improved later

swdave
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United States
Posted: 2nd Jul 2003 04:06
Windows manages the memory for you. What you CAN do is use a large resource a lot of times until Windows starts using the swap file then you can calculate back to measure your programs usage.

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 2nd Jul 2003 04:50
windows memory management? what do you mean?

when my dbp programs exit, they don't leave a trace of used memory - everything is released fine and i have the exact same memory going out as i had going in.

so feel free to elaborate what your mumbling about

The Wendigo
23
Years of Service
User Offline
Joined: 13th Sep 2002
Location: A hole near the base of a tree in the US
Posted: 2nd Jul 2003 05:24
Unfortunetely, it seems all that works in theory (however I'm talking from a win 98 standpoint). After a certain amount of compiles, my editor starts screwing up because I've exauhsted all my RAM. The only thing i can do is reboot. I did notice however, that if you manually delete all your objects when you exit your program, less residual memory is left. I still get the error, but not nearly as frequently. the new .NET framework is supposed to have an excellent garbage collector, but I have no idea if it works with all programs or just .NET programs.

Current Projects: Game Spawn 85%, mini BSP maker 50%, Height Mapper with many features 75%, Space Tactical (Like BC300AD) 15%.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 2nd Jul 2003 06:52
well i only have a problem with the editor when i do too much clipboard copying (ctrl-c/ctrl-v) god know why, as far as my system ram goes though its generall clears what it creates... perhaps thats more just a WindowsXP thing - i've never really used 98 so i dunno how it manages memory and i remember ME didn't have any problems either.

i generally compile my programs around 500-600 times a day when i'm actually coding, so it gets a bloody good work out and most of the time until i'm finalising code i don't bother setting up the quit where i generally delete everything.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jul 2003 09:53
I did a full (at the time) rundown on pointers in DBPro here : http://www.darkbasicpro.com/apollo/view.php?t=12270&b=1 - It's near the bottom of the page.

I've recently raised the bar a bit though with my array DLL (details in Program Announcements) that gives you pointers to structures.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 2nd Jul 2003 12:09
I think that if you free memory (and I presume it also encompasses DirectX handles etc), that Windows doesn't automatically put it back into the computers free pool (ie its still allocated/marked as being used) for a certain amount of time. Which, if its true, is rather stupid.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jul 2003 15:53
Heh, it's bother better and worse than that I'm afraid

If you allocate a big chunk of memory, say 100mb, and then allocate a little more, then free the large chunk, that 100mb is forever held by your process, until it terminates. New allocations *will* be taken from that 100mb first though, before you processes requests further memory from windows.

However, if nothing accesses that chunk, or for parts of that chunk that are not accessed (in 4kb blocks), eventually the memory will be committed to the swap file, freeing actual available memory, but still taking up swap space.

This is not a windows specific issue - it happens in all OS's that I'm aware of.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 2nd Jul 2003 18:34
if you setup the releases properly on exit you can get rid of the physical used memory ... unfortunately the page/swap memory will always be there until the application calls time-out

Windows actual management of memory isn't too bad, the only bad point about the setup is that it still uses a DOS base, so the sets you can use are limited in the chunks you can actually grab allocations - think last time i checked you could only grab utp 16mb at one time, so if you wanted to grab 100mb that'd split into 7chunks.

doesn't really take anything away, but atleast with pre-allocation you can access the memory much faster than when you need to reallocate extra space per chunk.
though i'm also pretty sure that with the exception of chunks this setup is common in most OS's

Login to post a reply

Server time is: 2026-07-17 13:57:53
Your offset time is: 2026-07-17 13:57:53