mirror of
https://github.com/silentwarble/PIC-Library
synced 2026-06-08 17:26:17 +00:00
Added notes for HeapAlloc vs VirtualAlloc
This commit is contained in:
+13
-1
@@ -88,6 +88,10 @@ uint32_t read_uint32(uint8_t **buffer)
|
||||
* You may not need to allocate on the heap. However,
|
||||
* unless you've accounted for stack size limitations
|
||||
* you may clobber the stack when reading large buffers.
|
||||
* It is advised you use HeapAlloc instead of VirtualAlloc. VirtuallAlloc allocates
|
||||
* at least 4kb (page). HeapAlloc will alloc just the bytes needed. This is important
|
||||
* in something as performance sensitive as serialization. You will need to track
|
||||
* the process heap pointer though.
|
||||
*/
|
||||
uint8_t* read_bytes(uint8_t **buffer, uint32_t length)
|
||||
{
|
||||
@@ -104,6 +108,10 @@ uint8_t* read_bytes(uint8_t **buffer, uint32_t length)
|
||||
/**
|
||||
* Expects that the string is null terminated. If not, you can use
|
||||
* the length param.
|
||||
* It is advised you use HeapAlloc instead of VirtualAlloc. VirtuallAlloc allocates
|
||||
* at least 4kb (page). HeapAlloc will alloc just the bytes needed. This is important
|
||||
* in something as performance sensitive as serialization. You will need to track
|
||||
* the process heap pointer though.
|
||||
*/
|
||||
char* read_string(uint8_t **buffer, uint32_t length)
|
||||
{
|
||||
@@ -124,6 +132,10 @@ char* read_string(uint8_t **buffer, uint32_t length)
|
||||
/**
|
||||
* Expects that the string is null terminated. If not, you can use
|
||||
* the length param.
|
||||
* It is advised you use HeapAlloc instead of VirtualAlloc. VirtuallAlloc allocates
|
||||
* at least 4kb (page). HeapAlloc will alloc just the bytes needed. This is important
|
||||
* in something as performance sensitive as serialization. You will need to track
|
||||
* the process heap pointer though.
|
||||
*/
|
||||
wchar_t* read_stringW(uint8_t **buffer, uint32_t length)
|
||||
{
|
||||
@@ -149,4 +161,4 @@ DWORD pic_htonl(DWORD hostlong)
|
||||
((hostlong & 0x00FF0000) >> 8) | // Move byte 2 to byte 1
|
||||
((hostlong & 0x0000FF00) << 8) | // Move byte 1 to byte 2
|
||||
((hostlong & 0x000000FF) << 24); // Move byte 0 to byte 3
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user