crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

memrealloc.cc (715B)


      1 #include "memory"
      2 
      3 void *Memory::realloc(void *ptr, size_t newsz, string const &desc) {
      4     static int lock;
      5     
      6     if (!newsz) {
      7 	free(ptr);
      8 	return 0;
      9     } else {
     10 	for (unsigned i = 0; i < s_memlog.size(); i++) {
     11 	    MemoryEntry ent = s_memlog[i];
     12 	    if (ent.ptr == ptr) {
     13 		ent.ptr = ::realloc(ptr, newsz);
     14 		ent.sz = newsz;
     15 		ent.desc = desc;
     16 		mutex_lock(&lock);
     17 		s_memlog[i] = ent;
     18 		mutex_unlock(&lock);
     19 		if (s_follow) {
     20 		    mutex_lock(&cout);
     21 		    cout << "Memory::realloc(" << ptr << ", " << newsz
     22 			 << ") -> " << ent.ptr << ' ' << desc << '\n';
     23 		    mutex_unlock(&cout);
     24 		}
     25 		return ent.ptr;
     26 	    }
     27 	}
     28 	cerr << "REALLOC Request for non previously allocated memory\n";
     29     }
     30     return 0;
     31 }