Created
May 4, 2014 22:17
-
-
Save Varriount/335018e9f5d9ed177743 to your computer and use it in GitHub Desktop.
Aligned Allocation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proc allocAligned(size, alignment: int): pointer = | |
| ## Allocates a block of memory whose address is aligned to `alignment` | |
| ## This is needed for the buffer accepted by ReadDirectoryChanges, which | |
| ## must be allocated on an int32 boundary. | |
| var address = alloc0(size) | |
| result = address | |
| while (cast[int](address) mod alignment) != 0: | |
| address = cast[pointer](cast[int](address)+1) | |
| # Move the memory to the correct address if needed, and then resize it. | |
| if address != result: | |
| moveMem(result, address, size + (alignment*2)) | |
| result = address |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment