Created
June 4, 2017 11:13
-
-
Save pvalienteverde/484c97e1fd83fdc14020a2ccbd12c37e to your computer and use it in GitHub Desktop.
AddressSanitizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : AddressSanitizer.cpp | |
// Author : Pedro Valiente Verde | |
// Version : | |
// Copyright : Your copyright notice | |
// Description : Hello World in C++, Ansi-style | |
//============================================================================ | |
#include <iostream> | |
#include <chrono> | |
#include <thread> | |
#include <cmath> | |
#include <typeinfo> | |
using namespace std; | |
// Hay que instalar: sudo dnf install libasan.x86_64 libasan-static.x86_64 | |
// Añadir: -lasan al linker de las librerias y la opcion del compialdor: -fsanitize=address | |
// Mas info: https://github.com/google/sanitizers/wiki/AddressSanitizer | |
class A { | |
public: | |
A()= default; | |
virtual ~A()=default; | |
}; | |
int main() { | |
auto memoria_ocupada = std::pow(2, 20) * 1000; | |
cout << "Tamaño a ocupar en bytes: " << memoria_ocupada << ", Mb: " | |
<< memoria_ocupada / 1000000 << endl; | |
auto limite_iteraciones = static_cast<int>(memoria_ocupada / (sizeof(A))); | |
cout << "Numero de objetos creados: " << limite_iteraciones << endl; | |
for (int i = 0; i < limite_iteraciones; i++) { | |
A *id = new A(); | |
} | |
//std::this_thread::sleep_for(std::chrono::milliseconds(5000)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instalacion: sudo dnf install libasan.x86_64 libasan-static.x86_64
Añadir -lasan al linker de las librerias y la opcion del compialdor: -fsanitize=address
Mas info: github y en clang sobre adress AddressSanitizer