/** * This function checks whether the given position lies within any of the * adjacent chunks. Internal chunks are tested first. * * @param position The position to test. * @param chunkID If position is inside one of the adjacent chunks then * this is set to the id of that chunk. If position is * not inside any chunks then it is left alone. * @return True if the point was in the adjacent chunks, false * otherwise. */ bool AdjacentChunkSet::test(const Vector3& position, ChunkID& chunkID) const { // dprintf( "Testing point (%f,%f,%f) against adj chunk set:\n", // position.x, position.y, position.z ); // Test internal chunks first. for (unsigned int i = 0; i < chunks_.size(); i++) { if (chunks_[i].chunkID[8] == 'i' && testChunk(position, i)) { chunkID = chunks_[i].chunkID; return true; } } // Test non-internal chunks next. for (unsigned int i = 0; i < chunks_.size(); i++) { if (chunks_[i].chunkID[8] != 'i' && testChunk(position, i)) { chunkID = chunks_[i].chunkID; return true; } } // dprintf( "\tNot in any chunk\n" ); return false; }
int main ( int argc , char *argv[] ) { if ( argc < 2 || argc > 2 ) { fprintf(stderr,"quarantine <bytes>\n"); return -1; } //mlockall(MCL_FUTURE); int64_t maxMem = atoi(argv[1]); // 1GB? int64_t chunkSize = 300000; int32_t n = 0; int32_t max = (int32_t)(maxMem / chunkSize) + 10; char *mem [ max ]; int64_t total = 0LL; for ( ; ; ) { mem[n] = (char *)malloc ( chunkSize ); if ( mem[n] == NULL ) break; total += chunkSize; n++; if ( total >= maxMem ) break; if ( (n % 1000) == 0 ) fprintf(stderr,"quarantine: alloc block #%"INT32"\n",n); } fprintf(stderr, "quarantine: grabbed %"INT32" chunks of ram for " "total of %"UINT64" : %s\n", n,total,strerror(errno)); fprintf(stderr, "quarantine: scanning grabbed mem for errors.\n"); int64_t badRam = 0; // scan each chunk for ( int32_t i = 0 ; i < n ; i++ ) { // erturns true if passes if ( testChunk ( (unsigned char *)mem[i], chunkSize ) ) free ( mem[i] ); // otherwise do not free it else { badRam += chunkSize; // and lock it up mlock ( mem[i] , chunkSize ); } if ( (i % 1000) == 0 ) fprintf(stderr,"quarantine: test block #%"INT32"\n",i); } if ( badRam ) { fprintf(stderr, "quarantine: quarantining %"UINT64" bytes of bad ram.\n", badRam); // sleep forever for ( ; ; ) sleep ( 100 ); } fprintf(stderr,"quarantine: all ram was good. exiting.\n"); return 0; }