Allocates memory from the unmanaged memory of the process by using the specified number of bytes
is there a function or something in C++ allows me to Allocate memory from the unmanaged memory of the process by using the specified number of bytes.
like in c# for exmapl:
_key = Marshal.AllocHGlobal(开发者_如何学编程key.P.Length * sizeof(UInt32) + key.S.Length * sizeof(UInt32));
In C++ (without CLI), all memory is unmanaged.
void * MyMem = new byte[MySize];
Just using the new
operator should cause the C++ libraries to allocate the memory from the unmanaged memory of the process. If you really really want to use just a number of bytes, you would need to use malloc
and then cast the pointer, but if that's what you want to do, you should consider just using plain C. Otherwise, if you need to use C++, I would recommend the new
operator and have it figure out the proper number of bytes:
//Allocate the memory
uint32_t *_key = new uint32_t[key.P.Length + key.S.Length];
//Do what you need with it
//Cleanup and deallocate the memory
delete[] _key;
Or in C:
//Allocate
uint32_t *_key = malloc(key.P.Length * sizeof(UInt32) + key.S.Length * sizeof(UInt32));
//Use
//Cleanup
free(_key);
精彩评论