alloc garbage collected?

Started by xDan, September 06, 2011, 05:06:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xDan

hello,

is alloc garbage collected? like, say, I allocate some data to a pointer that is a private variable of a process.. when the process dies, does it get cleaned up? or do I have to use free?

do allocations even get cleaned up when Bennu exits?

...

also, is there anything like a destructor for a type or struct, to allow freeing of allocated stuff there?

handsource-dyko

Don't count on it. It is possible to create memory leaks if you're uncarefull. Hence, this is why there are some unload functions in bennu.
Although I do get the feeling that some memory is cleaned up by the interpreter, but not everyting.

SplinterGU

Quote from: xDan on September 06, 2011, 05:06:49 PM
hello,

is alloc garbage collected? like, say, I allocate some data to a pointer that is a private variable of a process.. when the process dies, does it get cleaned up? or do I have to use free?

do allocations even get cleaned up when Bennu exits?

...

also, is there anything like a destructor for a type or struct, to allow freeing of allocated stuff there?

no, no garbage collector in bennugd... garbage collector is a bad programmer issue... all memory allocated by malloc* must be free by user...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

handsource-dyko

I think you have a good point here. Learning from memory leaks and about memory managment is quasi-educational. I think garbage collection makes programmers lazy? In bennu programmers can't get away with sloppyness! ;D

xDan

Come on, it's not like we're coding in C here  ;) I use a script language for ease of use...

I do understand that alloc should require free, I suppose, since they mirror the C functions..

But it would be really handy to have a destructor type thing for my user defined Types.. Perhaps even a constructor!

(obviously the built in types like string etc do their own garbage collection..)

Example:

[code language="bennu"]
Type MyVector
   
   int *stuff;
   
   construct
      stuff = malloc(...)
   end
   
   destruct
      free(stuff)
   end
end

// then can have functions to operate on these types

function vector_push(MyVector *vector, newelement)
begin
   vector->realloc, whatever...
end
[/code]

Something like that would make making my own more complex types possible... and I would be able to declare them as private variables of a process rather than having to create and free them manually (which is really annoying...)

SplinterGU

#5
I don't agree... you have malloc/free in bash or in cmd, shell script? nop...

this isn't c++ (or any language class like)...

bennugd don't have (and don't will have) garbage collector for malloc... the privater vars are free, but not pointers... a pointer can point to an allocated area or an initializate area... bennugd can't know if the point data is valid or no... or if you already free the allocated area already point to old data when the process die... neither can't know if you allocate data for a global use or for a private use (case of alloc in global vars).

garbage collector is an ugly invention.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

xDan

#6
yeah I agree with you there, my last post was suggesting something else ;)

...

at the moment, there is no way (correct me if wrong..) to make anything (in Bennu language itself) that works in a similar way to Bennu's built in types.

is this something you never intend to change?

obviously the built in string type dynamically allocates a buffer - and frees it when the process dies. you seem happy that we don't need to call free on strings when we've finished with them...

...

my main reason for asking all this is a desire to write my own vector and map types. Really, being limited to a fixed size array in this day and age is painful beyond measure... especially in an interpreted language which I obviously wouldn't be using for performance anyway..

so maybe I should also ask: do you ever intend to add map / associative array or vector / linked list type data structures to bennu?

handsource-dyko

I know a good  feature that would be really usefull: Dynamic arrays and/or string lists. This is a very nice feature in delphi/lazarus/free passcal, that I would like to have in bennu. I'm not too compelled to create my own mechanisms for this, as I feel that pointers and manual memory managment are too much of a low level concept for things like this. I have always used structs with nested arrays and for levelmaps fixed size arrays are fine, but for gui's/and texts dynamic data structures are usefull. I once experimented with a self-made file-selection dialogbox, and used processes to create a linked list because I knew that bennu sort of sets this up a dynamic memory structure.

SplinterGU

Download Lastest BennuGD Release: http://www.bennugd.org/node/2

xDan