z3 / src / test / memory.cpp

#ifdef _WINDOWS
#include "z3.h"
#include "z3_private.h"
#include <iostream>
#include "util.h"
#include "trace.h"

static bool oom = false;


static void err_handler(Z3_context c, Z3_error_code e) {
    oom = true;
    throw std::bad_alloc();
}

static void hit_me(char const* wm) {
    Z3_config cfg;
    Z3_context ctx;

    oom = false;

    cfg = Z3_mk_config();
    Z3_set_param_value(cfg, "MEMORY_MAX_SIZE", wm);
    ctx = Z3_mk_context(cfg);
    Z3_set_error_handler(ctx, &err_handler);
    
    unsigned i;
    for (i = 1; !oom ; ++i) {
        try {
            Z3_mk_bv_sort(ctx,i);      
			
        }
        catch (std::bad_alloc) {
            std::cout << "caught\n";
        }
    }

    std::cout << "oom " << i << "\n";
}

void tst_memory() {    
    hit_me("1");
    Z3_reset_memory();
    hit_me("2");
    Z3_reset_memory();
    hit_me("3");
    Z3_reset_memory();

}

#else
void tst_memory() {    
}
#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.