~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_block.c

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* functions on blocks; Keys and records are saved in blocks */
17
17
 
18
 
#include "heap_priv.h"
19
 
 
20
 
#include <cstdlib>
 
18
#include "heapdef.h"
21
19
 
22
20
/*
23
21
  Find record according to record-position.
24
 
 
25
 
  The record is located by factoring position number pos into (p_0, p_1, ...)
 
22
      
 
23
  The record is located by factoring position number pos into (p_0, p_1, ...) 
26
24
  such that
27
25
     pos = SUM_i(block->level_info[i].records_under_level * p_i)
28
26
  {p_0, p_1, ...} serve as indexes to descend the blocks tree.
49
47
    hp_get_new_block()
50
48
      block             HP_BLOCK tree-like block
51
49
      alloc_length OUT  Amount of memory allocated from the heap
52
 
 
53
 
  Interrupts are stopped to allow ha_panic in interrupts
 
50
      
 
51
  Interrupts are stopped to allow ha_panic in interrupts 
54
52
  RETURN
55
53
    0  OK
56
54
    1  Out of memory
67
65
 
68
66
  /*
69
67
    Allocate space for leaf block plus space for upper level blocks up to
70
 
    first level that has a free slot to put the pointer.
 
68
    first level that has a free slot to put the pointer. 
71
69
    In some cases we actually allocate more then we need:
72
70
    Consider e.g. a situation where we have one level 1 block and one level 0
73
 
    block, the level 0 block is full and this function is called. We only
74
 
    need a leaf block in this case. Nevertheless, we will get here with i=1
75
 
    and will also allocate sizeof(HP_PTRS) for non-leaf block and will never
 
71
    block, the level 0 block is full and this function is called. We only 
 
72
    need a leaf block in this case. Nevertheless, we will get here with i=1 
 
73
    and will also allocate sizeof(HP_PTRS) for non-leaf block and will never 
76
74
    use this space.
77
 
    This doesn't add much overhead - with current values of sizeof(HP_PTRS)
 
75
    This doesn't add much overhead - with current values of sizeof(HP_PTRS) 
78
76
    and my_default_record_cache_size we get about 1/128 unused memory.
79
77
   */
80
78
  *alloc_length=sizeof(HP_PTRS)*i+block->records_in_block* block->recbuffer;
81
 
  if (!(root=(HP_PTRS*) malloc(*alloc_length)))
 
79
  if (!(root=(HP_PTRS*) my_malloc(*alloc_length,MYF(MY_WME))))
82
80
    return 1;
83
81
 
84
82
  if (i == 0)
104
102
    block->level_info[i].last_blocks->
105
103
      blocks[HP_PTRS_IN_NOD - block->level_info[i].free_ptrs_in_block--]=
106
104
        (unsigned char*) root;
107
 
 
 
105
    
108
106
    /* Add a block subtree with each node having one left-most child */
109
107
    for (j=i-1 ; j >0 ; j--)
110
108
    {
112
110
      block->level_info[j].last_blocks->blocks[0]=(unsigned char*) root;
113
111
      block->level_info[j].free_ptrs_in_block=HP_PTRS_IN_NOD-1;
114
112
    }
115
 
 
116
 
    /*
 
113
    
 
114
    /* 
117
115
      root now points to last (block->records_in_block* block->recbuffer)
118
116
      allocated bytes. Use it as a leaf block.
119
117
    */