a few questions about optional map params, console, etc

Just starting out? Need help? Post your questions and find answers here.
nsstudios
Enthusiast
Enthusiast
Posts: 274
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

a few questions about optional map params, console, etc

Post by nsstudios »

Hi all :)

I would appreciate it so much if any of you could help demystify a few more things:
1. What exactly needs to be freed manually?
I know anything that is allocated manually also needs to be freed manually, and also functions that work with buffers often tell you to free the memory when you don't need it anymore, but what else do I have to free myself?
I've read a post about manually freeing strings in the structure, is that something we still have to do?
Also I've read how you're supposed to manually free dynamically added map elements...
If I have a structured array/list/map, is removing an element enough, or do I have to free/clear the structure it's attached to?
I'd appreciate if anyone could offer clarification.

2. Is it possible to have optional map procedure arguments?
I tried

Code: Select all

newMap myMap.myStruct()
; add elements
procedure test(map m.myStruct()=myMap())
but it didn't like that.
I also wonder if there's a way to accept all types of array/map/list as a procedure argument like internal pb functions do?

3. Is there a way to prevent my win32 program from killing itself when a console opened with openConsole() is closed by user and (if possible) catch the closed event?

Code: Select all

openConsole("test")
repeat
delay(1)
forever
if the user closes the console, the program ends as if the end keyword was used.

4. What's the best way to pass structures to a threaded procedure?
Which of these ways is better, or is there a better way all together? I assume the second one would need freeing while the first one wouldn't?

Code: Select all

Structure arg
i.i
s.s
EndStructure
Procedure test(*a.arg)
Debug *a\i
Debug *a\s
EndProcedure
; first
a.arg
a\s="test"
a\i=123
t1=CreateThread(@test(), a)
; second
*a.arg=AllocateMemory(SizeOf(arg))
*a\s="test"
*a\i=123
t2=CreateThread(@test(), *a)
Repeat
Delay(1)
Until Not IsThread(t1) And Not IsThread(t2)
Thanks.