.net - How to pin memory allocated by Marshal.AllocHGlobal() in C#? -
how pin memory allocated marshal.allochglobal()?
my first attempt following:
int bytes = 10; intptr ip = marshal.allochglobal(bytes); gchandle iph = gchandle.alloc(ip, gchandletype.pinned); although think pins intptr , not block of memory referred intptr.
the memory allocated allochglobal pinned. intptr returned address of pinned location.
update: pedantic can't "pin" memory allocated allochglobal, pin means tell garbage collector not move object in memory. memory allocated allochglobal "unmanaged memory" means memory not managed garbage collector.
no process besides garbage collector moves memory around in program, , garbage collector not care unmanaged resources.
Comments
Post a Comment