Example #1
0
static char *palloc(int *sizepos,int size,int *indxpos,BLK **blk)
/*
 * main allocation routine
 */
{
  BLK      *bp;
  char            *rv;
	if( size & 1 )		/* if odd size */
		size += 1;	/* make it even */
	/* if anything left, try to allocate from it */
  if( *sizepos >= size ) {
    rv = &((*blk)->m[*indxpos]);
    *sizepos -= size;
    *indxpos += size;
    return rv;
  }
  else    {
		long allocsize;
		/* else check for size > normal blcok size */
		if (size > 2048) {
			/* this is going to fragment memory!!! I'd fix it except
			 * the fragmentation is partially dependent on the calloc 
			 * implementation 
			 */
			allocsize = size - 1;
			*sizepos = 0;
		}
		else {
			/* as long as we stick to normal blocks, fragmentation
			 * won't be an issue because as long as all blocks are the
			 * same size calloc is guaranteed to find one if there are any
			 */
			allocsize = 2047;
			*sizepos = 2048 - size;
		}
		/* allocate mem */
    bp = calloc(1,sizeof(BLK) + allocsize);
		if( bp == NULL ) {
			release_global();
			release_local();
			release_opt();
			release_oc();
			mem_summary();
			fatal(" not enough memory.");
		}
		bp->blksize = allocsize;
		/* link the block and return the base */
    bp->next = *blk;
    *blk = bp;
    *indxpos = size;
    return (*blk)->m;
	}
}
void disconnect_after_connect(){
    init_global();
    clusterInfo *cluster = connectRedis("127.0.0.1",6667);
    if(cluster != NULL) {
        printf("connected to cluster\n");
    }else{
        printf("panic\n");
    }
    char key[10] = "key";
    char value[10] = "value";
    
    set(cluster,key,value,1,1);
    get(cluster,key,value,1,1);
    printf("get value= %s\n",value);
    
    disconnectDatabase(cluster);
    release_global();
}