[opengm] 47/50: trick to let clang not optimize mem-allocation away :-)
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Nov 1 17:14:50 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository opengm.
commit 92c9d098b3e984532b6579119c2cf403918a64da
Author: joergkappes <kappes at math.uni-heidelberg.de>
Date: Tue Oct 27 10:11:55 2015 +0100
trick to let clang not optimize mem-allocation away :-)
---
src/unittest/test_memoryinfo.cxx | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/unittest/test_memoryinfo.cxx b/src/unittest/test_memoryinfo.cxx
index 3d9f941..75c9210 100644
--- a/src/unittest/test_memoryinfo.cxx
+++ b/src/unittest/test_memoryinfo.cxx
@@ -13,7 +13,7 @@ int main(int argc, char** argv) {
std::cout << "--> allocate doubles (80.000k)" <<std::endl;
double *a = new double[10000*1024];
- for(size_t i=0; i<10000*1024; ++i) *(a+i) = i;
+ for(size_t i=0; i<10000*1024; ++i) a[i] = i;
std::cout << "New physical memory usage : "<<memInfo.usedPhysicalMem() << " kB" <<std::endl;
std::cout << "New virtual memory usage : "<<memInfo.usedVirtualMem() << " kB"<<std::endl;
@@ -23,6 +23,7 @@ int main(int argc, char** argv) {
// assert(memInfo.usedVirtualMem()<100000);
+
std::cout << "--> allocate doubles (80.000k)" <<std::endl;
double *b = new double[10000*1024];
for(size_t i=0; i<10000*1024; ++i) *(b+i) = i;
@@ -34,13 +35,15 @@ int main(int argc, char** argv) {
OPENGM_TEST(memInfo.usedPhysicalMem()<180000);
// assert(memInfo.usedVirtualMem()<180000);
- std::cout << "<-- free first doubles" <<std::endl;
+ std::cout << "<-- free first doubles" <<std::endl;
+ std::cout << "Ones use the mem, otherwise clang optimize it away ;-) " << a[10000*1024-1]<<std::endl;
delete a;
std::cout << "New physical memory usage : "<<memInfo.usedPhysicalMem() << " kB" <<std::endl;
std::cout << "New virtual memory usage : "<<memInfo.usedVirtualMem() << " kB" <<std::endl;
std::cout << "<-- free second doubles" <<std::endl;
+ std::cout << "Ones use the mem, otherwise clang optimize it away ;-) " << b[10000*1024-1]<<std::endl;
delete b;
std::cout << "New physical memory usage : "<<memInfo.usedPhysicalMem() << " kB" <<std::endl;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opengm.git
More information about the debian-science-commits
mailing list