[Implemented] ClearMemory(*buffer,size)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

[Implemented] ClearMemory(*buffer,size)

Post by Rook Zimbabwe »

I have been twiddling with the peek and poke series and think PB needs an easy and efficent way to CLEAR a *buffer memory. :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

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

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))
Thalius
"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! ;)"
Post Reply