Redim + thread

General FreeBASIC programming questions.
Post Reply
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Redim + thread

Post by Provoni »

Suppose the following code with multiple threads running it:

Code: Select all

sub thread(byval pointer as any ptr)
	
	dim array()
	
	do
		
		if new_data=1 then
			
			if check=1 then redim array(a,b,c)
			
			'do calculations
			
		end if
		
		'report back the main thread
		
	loop until user_terminated=1
	
end sub
Is the array placed on the stack or not? If not, is it possible to do from inside the thread?
Does the redim guarantee that any previous data in the array is cleared?

Thanks
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Redim + thread

Post by fxm »

'dim array()' defines a var-len array with:
- its descriptor on the stack,
- its elements in the heap (only a non-static and fix-len array has its elements on the stack).
The only difference from classic subs is that each thread has its own stack.

'redim' ensures that all previous data in the array is destroyed.
'redim preserve' only destroys previous data not preserved by resizing.
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Redim + thread

Post by Provoni »

Thank you very much
Post Reply