Ref: http://www.purebasic.fr/english/viewtopic.php?t=23930
For networking by sending and rec bytes (not strings). How in the world have you guys figured out how to make a data (byte) buffer when MemorySize() returns old size (due to an OS, thanks Windows! limitation). 
For instance, if I wanted to free the client buffer, I would use FreeMemory(*ClientBuffer), but then MemorySize(*ClientBuffer) still have the info. So, when I attach the additional data to the buffer, it is bigger when it shouldnt ..
So basically, my question is for all you network gurus out there ... how did you get around this OS limitation?
			
			
									
									
						How to have a data buffer?
I don't understand the problem. After you have used FreeMemory(Memory) assume that the memory is no more and do not place anything there.
If you need a way to check whether you have freed some memory, set the memory pointer to 0 after every call to FreeMemory():
But, if you're relying on MemorySize to check whether the buffer is initialized you are doing dangerous coding. Only rely on the return value of AllocateMemory() and on a call to FreeMemory() for that.
So if you called AllocateMemory() and the return value was 0 then the memory is not allocated. Else the memory is allocated until you call FreeMemory(). No other PB calls can check it, if you can't keep track of it using program flow you must make a variable for it (or set the memory pointer to 0).
Don't attach data to a buffer you've freed!
			
			
									
									
						If you need a way to check whether you have freed some memory, set the memory pointer to 0 after every call to FreeMemory():
Code: Select all
Macro FreeMemorySafe(Memory)
  FreeMemory(Memory)
  Memory = 0
EndMacro
Memory = AllocateMemory(49)
Debug MemorySize(Memory)
FreeMemorySafe(Memory)
Debug MemorySize(Memory)So if you called AllocateMemory() and the return value was 0 then the memory is not allocated. Else the memory is allocated until you call FreeMemory(). No other PB calls can check it, if you can't keep track of it using program flow you must make a variable for it (or set the memory pointer to 0).
Code: Select all
So, when I attach the additional data to the bufferI think there's some misunderstanding. I attach data to an existing buffer. For instance, the *ClientBuffer will grow until a complete packet is recieved, then it's parse out, and shrinked down.
The Memory=0 is a great idea though. That'll work to blank out the buffer completely.
I rely on MemorySize() usually to see the size of an existing buffer, the buffer I will use to attach to. Then I do something like *ClientBuffer = ReAllocateMemory(memorysize(*clientbuffer) + memorysize(*newbuffer)).
This will reallocate, then I can take the memorysize(*clientbuffer) + 1 as the address to Movememory or copymemory of the new buffer onto the end of the client buffer
I think the Memory = 0 will do the trick 
  
Thank you very much!
			
			
									
									
						The Memory=0 is a great idea though. That'll work to blank out the buffer completely.
I rely on MemorySize() usually to see the size of an existing buffer, the buffer I will use to attach to. Then I do something like *ClientBuffer = ReAllocateMemory(memorysize(*clientbuffer) + memorysize(*newbuffer)).
This will reallocate, then I can take the memorysize(*clientbuffer) + 1 as the address to Movememory or copymemory of the new buffer onto the end of the client buffer

I think the Memory = 0 will do the trick
 
  Thank you very much!

