Category : memory

I have a std::vector<const char*> which I populate by .push_back("something"). How to delete contents not including std::string‘s header? delete segfaults, and std::free needs void* and it "cannot initialize [..] with an lvalue of type ‘const char *’". Source: Windows Que..

Read more

Goal: I want to retrieve the file paths of dynamic libraries loaded by a process. My code: struct task_dyld_info dyld_info; mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT; struct dyld_image_info dyld_image_info; char path[PATH_MAX]; if (task_info(task, TASK_DYLD_INFO, (task_info_t) & dyld_info, & count) == KERN_SUCCESS) { printf("dyld_all_image_infos: %pn", dyld_info.all_image_info_addr); printf("%dn", dyld_info.all_image_info_size); struct dyld_all_image_infos * dyld_all_image_infos = (struct dyld_all_image_infos * ) dyld_info.all_image_info_addr; ..

Read more

While testing some things regarding page faults I discovered a curious difference between how new operates in Debug mode and Release mode in MSVC. Consider the following code1: #include <array> constexpr size_t PAGE_SIZE = 4096; int main() { const size_t count = 1000000; char* const mem = new char[PAGE_SIZE * count]; // page align the ..

Read more

When I first learned C++, I avoided STL because the project I was contributing to didn’t use it all (still don’t know why). Here’s how we did things instead. First, we have a memory class which houses a template function, which looks like this: /* ———————————————————————- create a 1d array ————————————————————————- */ template <typename TYPE> ..

Read more

I’m writing a sample code for creating a process memory dump using the MiniDumpWriteDump API. The call works fine with the MiniDumpNormal type but not with the MiniDumpWithFullMemory type. Here’s the code sample: int main() { LPCWSTR lPath = L"C:UsersxDesktoptest.dmp"; HANDLE hFile = CreateFile(lPath, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, ..

Read more