I miss memset. I have a frame buffer in a class, it has data in it from some other operations, and now I want to clear everything in that frame buffer to 0x00 or 0xFF. I didn't see a clear method in the docs, there's a zfill method that might work. I thought about just calling the init method of the byte array again but wondered if that might cause me some memory trouble down the road.
I'm using python 2.7.
The bytearray() function returns a bytearray object. It can convert objects into bytearray objects or create an empty bytearray object of the specified size. Some rules are followed by the bytearray() function depending on the source type. If no argument is passed, an empty byte array is returned.
Python bytearray() Function The bytearray() function returns a bytearray object. It can convert objects into bytearray objects, or create empty bytearray object of the specified size.
bytearray() method returns a bytearray object which is an array of given bytes. It gives a mutable sequence of integers in the range 0 <= x < 256. Returns: Returns an array of bytes of the given size. source parameter can be used to initialize the array in few different ways.
Python is not C, here you don't need to worry about memory at all much. You just simply do:
a = bytearray("abcd") # initialized it with real data
a = bytearray(5) # just a byte array of size 5 filled with zeros
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With