#include #include int func1() { // Allocate memory for an array of 5 integers int* arr1 = (int*)malloc(5 * sizeof(int)); // Check if the allocation was successful if (arr1 == nullptr) { std::cerr << "Memory allocation failed" << std::endl; return 1; } // Initialize the array for (int i = 0; i < 5; ++i) { arr1[i] = i * 2; } // Print the array std::cout << "Array 1 elements:" << std::endl; for (int i = 0; i < 5; ++i) { std::cout << arr1[i] << " "; } std::cout << std::endl; // Resize the array to hold 10 integers int* newArr1 = (int*)realloc(arr1, 10 * sizeof(int)); // Check if the reallocation was successful if (newArr1 == nullptr) { std::cerr << "Memory reallocation failed" << std::endl; free(arr1); // Free the original memory block return 1; } // Initialize the new elements for (int i = 5; i < 10; ++i) { newArr1[i] = i * 2; } // Print the resized array std::cout << "Resized array elements:" << std::endl; for (int i = 0; i < 10; ++i) { std::cout << newArr1[i] << " "; } std::cout << std::endl; // Free the allocated memory free(newArr1); return 0; } int func4(){ SIZE_T size = 1024 * 1024; LPVOID lpAddress = VirtualAlloc( NULL, // Let the system determine the address size, // Size of the memory block MEM_COMMIT | MEM_RESERVE, // Allocate and reserve memory PAGE_READWRITE // Read and write access ); // Check if the allocation was successful if (lpAddress == NULL) { std::cerr << "Memory allocation failed with error: " << GetLastError() << std::endl; return 1; } std::cout << "Memory allocated at address: " << lpAddress << std::endl; // Use the allocated memory (example: fill with zeros) memset(lpAddress, 0, size); // Free the allocated memory if (!VirtualFree(lpAddress, 0, MEM_RELEASE)) { std::cerr << "Memory free failed with error: " << GetLastError() << std::endl; return 1; } std::cout << "Memory freed successfully." << std::endl; return 0; } void main() { std::cout << "hello ------- pdb test" << std::endl; func1(); func4(); }