Root > Reference > All Functions > AllocatePageAlign

Function AllocatePageAlign

Previous pageReturn to chapter overviewNext page   

Allocates memory with alignment on current memory's page size boundary.

 

Unit

ELowLevel

 

Syntax

 

Code (Delphi)

function AllocatePageAlign(

const ASize: Cardinal;

out AHolder: Pointer

): Pointer;

 

Parameters

ASize [in]

Size of memory block to allocate in bytes.

 

AHolder [out]

a pointer to backbone storage. This is the pointer which must be passed to FreeMem to release this memory block.

 

Return value

A pointer to memory block of ASize bytes aligned at page boundary.

 

Exceptions

System.SysUtils.EOutOfMemory

Not enought memory to perform request.

 

Remarks

This function is the same as AllocMem except it also aligns result on memory's page size boundary.

 

That's it, if memory's page size is 4 Kb - then result is always aligned on 4 Kb (i.e. have 12 zeros at low part of pointer when represented in binary).

 

Thus, this function have an overhead of maximum 2 size of memory's page. For example, if memory's page size is 4 Kb - then this function will allocate 12 Kb for ASize less than 4 Kb, 16 Kb - for ASize less than 8 Kb and so on.

 

You shouldn't pass returned pointer to any memory releasing routines (like FreeMem). Instead, call FreeMem for AHolder.

 

Note

Page size may be different on different platforms. Do not make any assumptions about it.

 

You can get current page size by calling PageSize.

 

See also

AllocMem



Send feedback... Build date: 2024-09-30
Last edited: 2024-09-30
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/topic_function_elowlevel_allocatepagealign.php