/** \brief Reallocates a buffer allocated with emalloc(). \param [in] Pointer to memory previously allocated with emalloc(). When NULL a new buffer will be allocated by emalloc(). \param size The new memory size. \param reason The reason for allocation (can be used for memory allocation tracking). \return Always returns a valid pointer to the buffer you requested. Will quit the application on errors. */ void* erealloc(void* ptr, size_t size, const char* reason) { ASSERT_NONZERO(size); // Free the memory if the pointer was set (as per documentation). if(ptr) efree(ptr); return emalloc(size, reason); }
int test_celegans() { plfit_result_t result; plfit_discrete_options_t options; size_t n; plfit_discrete_options_init(&options); options.p_value_method = PLFIT_P_VALUE_SKIP; n = test_read_file("celegans-indegree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, &options, &result); ASSERT_ALMOST_EQUAL(result.alpha, 2.9967, 1e-1); ASSERT_EQUAL(result.xmin, 10); ASSERT_ALMOST_EQUAL(result.L, -245.14869, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.04448, 1e-3); n = test_read_file("celegans-outdegree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, &options, &result); ASSERT_ALMOST_EQUAL(result.alpha, 3.3778, 1e-1); ASSERT_EQUAL(result.xmin, 11); ASSERT_ALMOST_EQUAL(result.L, -232.80207, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.08615, 1e-3); n = test_read_file("celegans-totaldegree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, &options, &result); ASSERT_ALMOST_EQUAL(result.alpha, 3.29264, 1e-1); ASSERT_EQUAL(result.xmin, 18); ASSERT_ALMOST_EQUAL(result.L, -315.78214, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.04760, 1e-3); return 0; }
int test_celegans() { plfit_result_t result; size_t n; n = test_read_file("celegans-indegree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, 0, &result); ASSERT_ALMOST_EQUAL(result.alpha, 2.9967, 1e-1); ASSERT_EQUAL(result.xmin, 10); ASSERT_ALMOST_EQUAL(result.L, -245.14869, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.04448, 1e-3); ASSERT_ALMOST_EQUAL(result.p, 0.9974, 1e-3); n = test_read_file("celegans-outdegree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, 0, &result); ASSERT_ALMOST_EQUAL(result.alpha, 3.3778, 1e-1); ASSERT_EQUAL(result.xmin, 11); ASSERT_ALMOST_EQUAL(result.L, -232.80207, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.08615, 1e-3); ASSERT_ALMOST_EQUAL(result.p, 0.6076, 1e-3); n = test_read_file("celegans-totaldegree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, 0, &result); ASSERT_ALMOST_EQUAL(result.alpha, 3.29264, 1e-1); ASSERT_EQUAL(result.xmin, 18); ASSERT_ALMOST_EQUAL(result.L, -315.78214, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.04760, 1e-3); ASSERT_ALMOST_EQUAL(result.p, 0.98610, 1e-3); return 0; }
int test_condmat() { plfit_result_t result; size_t n; n = test_read_file("condmat2005-degree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, 0, &result); ASSERT_ALMOST_EQUAL(result.alpha, 3.68612, 1e-2); ASSERT_EQUAL(result.xmin, 49); ASSERT_ALMOST_EQUAL(result.L, -3152.48302, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.02393, 1e-3); ASSERT_ALMOST_EQUAL(result.p, 0.79117, 1e-3); return 0; }
/** \brief Allocates a new buffer. \param size The size of the buffer to allocate (in bytes). \param reason The reason for allocation (can be used for memory allocation tracking). \return Always returns a valid pointer to the buffer you requested. Will quit the application on errors. */ void* emalloc(size_t size, const char* reason) { ASSERT_NONZERO(size); unsigned char* a = (unsigned char*)GlobalAlloc(GMEM_FIXED, size); if(!a) { MessageBoxA(0, "Could not allocate memory", "Error", MB_ICONERROR); ExitProcess(1); } memset(a, 0, size); emalloc_count++; /* FILE* file = fopen(alloctrace, "a+"); fprintf(file, "DBG%.5d: alloc:" fhex ":%s:" fhex "\n", emalloc_count, a, reason, size); fclose(file); */ return a; }
int test_condmat() { plfit_result_t result; plfit_discrete_options_t options; size_t n; plfit_discrete_options_init(&options); options.p_value_method = PLFIT_P_VALUE_SKIP; n = test_read_file("condmat2005-degree.dat", data, 41000); ASSERT_NONZERO(n); result.alpha = result.xmin = result.L = 0; plfit_discrete(data, n, &options, &result); ASSERT_ALMOST_EQUAL(result.alpha, 3.68612, 1e-2); ASSERT_EQUAL(result.xmin, 49); ASSERT_ALMOST_EQUAL(result.L, -3152.48302, 1e-4); ASSERT_ALMOST_EQUAL(result.D, 0.02393, 1e-3); return 0; }