Beispiel #1
0
// Get a pointer to the node label
int* oc_bpt_label_get(struct Oc_wu *wu_p, Oc_bpt_node *node_p)
{
    uint64 disk_addr = node_p->disk_addr;
    Oc_bpt_label_cell *cell_p;
    
    /* Lookup the cell.
     *
     * If it exists, return a pointer to the value.
     */
    cell_p = oc_bpt_label_lookup(disk_addr);
    if (cell_p != NULL)
        return &cell_p->val;

    /* Otherwise, create
     * a cell and insert it into the table.
     */

    // create a new cell 
    cell_p = (Oc_bpt_label_cell*) pl_mm_malloc(sizeof(Oc_bpt_label_cell));
    memset(cell_p, 0, sizeof(Oc_bpt_label_cell));
    cell_p->addr = disk_addr;

    // insert into the table
    oc_bpt_label_insert(cell_p);
    return &cell_p->val;
}
Beispiel #2
0
Datei: pl_mm.c Projekt: orodeh/bt
/*
  [Allon 11/1/06] added a member called all_objects_pp which saves
  addresses of all allocated objects so they can be released on pool delete.
  memory overhead could be reduced if we allocate many objects in one malloc.
  (I didn't want to allocated them all at once because it may be a very
  large malloc)
 */
bool pl_mm_pool_create( uint32 size_i,
                        Pl_mm_alignment_t align_i,
                        uint32 number_i,
                        void (*init_object_i)( void *object_i),
                        Pl_mm_op **pool_o )
{
    Pl_mm_op *new_pool ;
    uint32 i;
    char *obj;
    int aligned_size;

    if (size_i < sizeof(int))
        ERR(("can't create a memory pool for objects smaller than an integer"));
    if (size_i < sizeof(void*))
        ERR(("can't create a memory pool for objects smaller than a pointer"));

    new_pool = (Pl_mm_op*) pl_mm_malloc(sizeof(Pl_mm_op_s));

    memset(new_pool, 0, sizeof(Pl_mm_op_s));
    new_pool->size = size_i;
    new_pool->number = number_i;
    new_pool->all_objects_pp =
        (void**) pl_mm_malloc( sizeof(void*) * number_i );
    memset( new_pool->all_objects_pp, 0, sizeof(void*) * number_i );
    *pool_o = new_pool;
    ssslist_init(&new_pool->free_list);

    aligned_size = align(size_i, align_i);
    for (i=0; i<number_i ; i++) {
	obj = (char*) pl_mm_malloc (aligned_size);
	memset(obj, 0, aligned_size);
        new_pool->all_objects_pp[i] = (void*)obj;

	if (NULL != init_object_i)
	    (*init_object_i)(obj);
	ssslist_add_tail(&new_pool->free_list, (Ss_slist_node*)obj);
    }
    return TRUE;
}
Beispiel #3
0
static struct Oc_bpt_test_fs_ctx *fs_create(
    char *str_desc_p,
    int num_blocks,
    bool verbose)
{
    struct Oc_bpt_test_fs_ctx *fs_p;
    
    fs_p = (struct Oc_bpt_test_fs_ctx *)
        pl_mm_malloc(sizeof(struct Oc_bpt_test_fs_ctx));

    memset(fs_p, 0, sizeof(struct Oc_bpt_test_fs_ctx));
    fs_p->num_blocks = num_blocks;
    fs_p->fs_array = (char*) pl_mm_malloc(num_blocks);
    memset(fs_p->fs_array, 0, num_blocks);
    memset(fs_p->desc, 0, 30);
    strncpy(fs_p->desc, str_desc_p, 30);
    fs_p->verbose = verbose;

    // don't allocate the first block
    fs_p->fs_array[0] = 1;

    return fs_p;
}