Версия с использованием malloc:
Код: Выделить всё
#include
int main() {
int* a = (int *)malloc(4);
return 0;
}
Код: Выделить всё
==34673== HEAP SUMMARY:
==34673== in use at exit: 4 bytes in 1 blocks
==34673== total heap usage: 1 allocs, 0 frees, 4 bytes allocated
Код: Выделить всё
int main() {
int* a = new int;
return 0;
}
Код: Выделить всё
==35295== HEAP SUMMARY:
==35295== in use at exit: 4 bytes in 1 blocks
==35295== total heap usage: 2 allocs, 1 frees, 72,708 bytes allocated
Кроме того, накладные расходы составляют 72 704 Б, даже если я использую только этот код:
Код: Выделить всё
#include
int main() {
return 0;
}
Код: Выделить всё
g++ --version
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
valgrind --version
valgrind-3.18.1
Подробнее здесь: https://stackoverflow.com/questions/787 ... d-new-in-c