
[Implemented] ClearMemory(*buffer,size)
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
[Implemented] ClearMemory(*buffer,size)
I have been twiddling with the peek and poke series and think PB needs an easy and efficent way to CLEAR a *buffer memory. 

If you dont want to allocate new, you could probably use this:
Using Longs is prolly faster than using bytes, tho not sure how its with data. This is basically what i came up with in 10 Mins
EDIT: lol damn too slow post =P as i see in Coding Questions
Thalius
Using Longs is prolly faster than using bytes, tho not sure how its with data. This is basically what i came up with in 10 Mins

EDIT: lol damn too slow post =P as i see in Coding Questions
Code: Select all
; Clear Membuffer (MAKE SURE SIZE IS NOT LARGER THAN BUFFER!)
Procedure ClearMemory(*Buffer,Size.l)
Protected *cptr.Long = *Buffer
If *Buffer And Size
For i = 0 To Size Step 4
*cptr\l = 0 : *cptr + i
Debug i
Next
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
; Struct for our Memory
Structure _a
x.l
y.l
EndStructure
#BufferSize = 128
*mem = AllocateMemory(#BufferSize)
*ptr._a = *mem
; Fill in Values
*ptr\x = 5
*ptr\y = 8
; Check Values with PeekL
Debug PeekL(*ptr)
Debug PeekL(*ptr+SizeOf(_a\x))
; Clear
Debug "Clear: "+Str(ClearMemory(*ptr,#BufferSize))
; Check Values with PeekL
Debug PeekL(*ptr)
Debug PeekL(*ptr+SizeOf(_a\x))
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone!
"
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone!
