What is the reference count for memory

new topic     » topic index » view thread      » older message » newer message

In the memory allocation routines there is an optional parameter 'cleanup'.
If this is set the memory is released when a reference count reaches zero.
How is the reference count increased and decreased?
Would the reference count reach zero when the allocated memory is used as a parameter to a function or procedure and the call is completed?
The following code is a Windows XP example.

include std/dll.e 
include std/machine.e 
atom lib, get_attr, Result 
sequence cmd 
cmd = command_line()		-- Get a file for it to work on 
lib = open_dll("kernel32.dll") 
get_attr = define_c_func(lib, "GetFileAttributesA",{C_POINTER}, C_INT) 
 
--		The next line is the important bit. 
Result = c_func(get_attr,{allocate_string(cmd[2],1)}) 
--		Does Euphoria release this memory automatically when the call completes? 
 
--		The rest just confirms it got something 
include get.e 
printf(1,"%08x",Result) 
puts(1,"\nPress a key") 
if wait_key() then end if 
new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu