De functie heb ik ptruint uint van gemaakt. Adres(a) deugt. freemem gaat ook goed. Als de functie slaagt wil ik daarna CreateDIBSection(....., hSection=hMapfile) aanroepen en dan hopen dat deze GEEN memory alloceert.
Code:
procedure Test;
function allocatealigned(nrbytes,nralign:integer;var pold:pbyte):pbyte;
var n:uint;
begin
getmem(pold,uint(nrbytes)+uint(nralign));
n:=(uint(nralign)-(uint(pold) and (uint(nralign)-1))) and (uint(nralign)-1); // second "AND" is to transform 1..nralign to 0..nralign-1
result:=@pold[n];
end;
const
k4=4096;
k8=8192;
gran=65536; // deze gebruik ik
var
hMapFile: THandle;
pBuf: pointer;
a,b: PByte;
begin
a := allocatealigned(20, gran, b);
log(NativeInt(a) mod gran);
hMapFile := CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_READWRITE,0,20,nil);
pBuf := MapViewOfFileEx(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 20, a);
log('last error ', GetLastError.ToString);
if pBuf = nil then
log('buf = nil')
else
log('buf = OK!');
end;
Bookmarks