1 | *** pool.hpp.~1.16.~ 2006-12-04 07:03:38.000000000 -0800
|
---|
2 | --- pool.hpp 2007-02-15 11:47:00.000000000 -0800
|
---|
3 | ***************
|
---|
4 | *** 287,297 ****
|
---|
5 | details::PODptr<size_type> prev;
|
---|
6 |
|
---|
7 | // This is a current & previous iterator pair over the free memory chunk list
|
---|
8 | ! // Note that "prev_free" in this case does NOT point to the previous memory
|
---|
9 | // chunk in the free list, but rather the last free memory chunk before the
|
---|
10 | // current block.
|
---|
11 | ! void * free = this->first;
|
---|
12 | ! void * prev_free = 0;
|
---|
13 |
|
---|
14 | const size_type partition_size = alloc_size();
|
---|
15 |
|
---|
16 | --- 287,297 ----
|
---|
17 | details::PODptr<size_type> prev;
|
---|
18 |
|
---|
19 | // This is a current & previous iterator pair over the free memory chunk list
|
---|
20 | ! // Note that "prev_freeptr" in this case does NOT point to the previous memory
|
---|
21 | // chunk in the free list, but rather the last free memory chunk before the
|
---|
22 | // current block.
|
---|
23 | ! void * freeptr = this->first;
|
---|
24 | ! void * prev_freeptr = 0;
|
---|
25 |
|
---|
26 | const size_type partition_size = alloc_size();
|
---|
27 |
|
---|
28 | ***************
|
---|
29 | *** 300,309 ****
|
---|
30 | {
|
---|
31 | // At this point:
|
---|
32 | // ptr points to a valid memory block
|
---|
33 | ! // free points to either:
|
---|
34 | // 0 if there are no more free chunks
|
---|
35 | // the first free chunk in this or some next memory block
|
---|
36 | ! // prev_free points to either:
|
---|
37 | // the last free chunk in some previous memory block
|
---|
38 | // 0 if there is no such free chunk
|
---|
39 | // prev is either:
|
---|
40 | --- 300,309 ----
|
---|
41 | {
|
---|
42 | // At this point:
|
---|
43 | // ptr points to a valid memory block
|
---|
44 | ! // freeptr points to either:
|
---|
45 | // 0 if there are no more free chunks
|
---|
46 | // the first free chunk in this or some next memory block
|
---|
47 | ! // prev_freeptr points to either:
|
---|
48 | // the last free chunk in some previous memory block
|
---|
49 | // 0 if there is no such free chunk
|
---|
50 | // prev is either:
|
---|
51 | ***************
|
---|
52 | *** 313,319 ****
|
---|
53 | // If there are no more free memory chunks, then every remaining
|
---|
54 | // block is allocated out to its fullest capacity, and we can't
|
---|
55 | // release any more memory
|
---|
56 | ! if (free == 0)
|
---|
57 | return ret;
|
---|
58 |
|
---|
59 | // We have to check all the chunks. If they are *all* free (i.e., present
|
---|
60 | --- 313,319 ----
|
---|
61 | // If there are no more free memory chunks, then every remaining
|
---|
62 | // block is allocated out to its fullest capacity, and we can't
|
---|
63 | // release any more memory
|
---|
64 | ! if (freeptr == 0)
|
---|
65 | return ret;
|
---|
66 |
|
---|
67 | // We have to check all the chunks. If they are *all* free (i.e., present
|
---|
68 | ***************
|
---|
69 | *** 321,368 ****
|
---|
70 | bool all_chunks_free = true;
|
---|
71 |
|
---|
72 | // Iterate 'i' through all chunks in the memory block
|
---|
73 | ! // if free starts in the memory block, be careful to keep it there
|
---|
74 | ! void * saved_free = free;
|
---|
75 | for (char * i = ptr.begin(); i != ptr.end(); i += partition_size)
|
---|
76 | {
|
---|
77 | // If this chunk is not free
|
---|
78 | ! if (i != free)
|
---|
79 | {
|
---|
80 | // We won't be able to free this block
|
---|
81 | all_chunks_free = false;
|
---|
82 |
|
---|
83 | ! // free might have travelled outside ptr
|
---|
84 | ! free = saved_free;
|
---|
85 | // Abort searching the chunks; we won't be able to free this
|
---|
86 | // block because a chunk is not free.
|
---|
87 | break;
|
---|
88 | }
|
---|
89 |
|
---|
90 | ! // We do not increment prev_free because we are in the same block
|
---|
91 | ! free = nextof(free);
|
---|
92 | }
|
---|
93 |
|
---|
94 | ! // post: if the memory block has any chunks, free points to one of them
|
---|
95 | // otherwise, our assertions above are still valid
|
---|
96 |
|
---|
97 | const details::PODptr<size_type> next = ptr.next();
|
---|
98 |
|
---|
99 | if (!all_chunks_free)
|
---|
100 | {
|
---|
101 | ! if (is_from(free, ptr.begin(), ptr.element_size()))
|
---|
102 | {
|
---|
103 | std::less<void *> lt;
|
---|
104 | void * const end = ptr.end();
|
---|
105 | do
|
---|
106 | {
|
---|
107 | ! prev_free = free;
|
---|
108 | ! free = nextof(free);
|
---|
109 | ! } while (free && lt(free, end));
|
---|
110 | }
|
---|
111 | // This invariant is now restored:
|
---|
112 | ! // free points to the first free chunk in some next memory block, or
|
---|
113 | // 0 if there is no such chunk.
|
---|
114 | ! // prev_free points to the last free chunk in this memory block.
|
---|
115 |
|
---|
116 | // We are just about to advance ptr. Maintain the invariant:
|
---|
117 | // prev is the PODptr whose next() is ptr, or !valid()
|
---|
118 | --- 321,368 ----
|
---|
119 | bool all_chunks_free = true;
|
---|
120 |
|
---|
121 | // Iterate 'i' through all chunks in the memory block
|
---|
122 | ! // if freeptr starts in the memory block, be careful to keep it there
|
---|
123 | ! void * saved_freeptr = freeptr;
|
---|
124 | for (char * i = ptr.begin(); i != ptr.end(); i += partition_size)
|
---|
125 | {
|
---|
126 | // If this chunk is not free
|
---|
127 | ! if (i != freeptr)
|
---|
128 | {
|
---|
129 | // We won't be able to free this block
|
---|
130 | all_chunks_free = false;
|
---|
131 |
|
---|
132 | ! // freeptr might have travelled outside ptr
|
---|
133 | ! freeptr = saved_freeptr;
|
---|
134 | // Abort searching the chunks; we won't be able to free this
|
---|
135 | // block because a chunk is not free.
|
---|
136 | break;
|
---|
137 | }
|
---|
138 |
|
---|
139 | ! // We do not increment prev_freeptr because we are in the same block
|
---|
140 | ! freeptr = nextof(freeptr);
|
---|
141 | }
|
---|
142 |
|
---|
143 | ! // post: if the memory block has any chunks, freeptr points to one of them
|
---|
144 | // otherwise, our assertions above are still valid
|
---|
145 |
|
---|
146 | const details::PODptr<size_type> next = ptr.next();
|
---|
147 |
|
---|
148 | if (!all_chunks_free)
|
---|
149 | {
|
---|
150 | ! if (is_from(freeptr, ptr.begin(), ptr.element_size()))
|
---|
151 | {
|
---|
152 | std::less<void *> lt;
|
---|
153 | void * const end = ptr.end();
|
---|
154 | do
|
---|
155 | {
|
---|
156 | ! prev_freeptr = freeptr;
|
---|
157 | ! freeptr = nextof(freeptr);
|
---|
158 | ! } while (freeptr && lt(freeptr, end));
|
---|
159 | }
|
---|
160 | // This invariant is now restored:
|
---|
161 | ! // freeptr points to the first free chunk in some next memory block, or
|
---|
162 | // 0 if there is no such chunk.
|
---|
163 | ! // prev_freeptr points to the last free chunk in this memory block.
|
---|
164 |
|
---|
165 | // We are just about to advance ptr. Maintain the invariant:
|
---|
166 | // prev is the PODptr whose next() is ptr, or !valid()
|
---|
167 | ***************
|
---|
168 | *** 380,389 ****
|
---|
169 | list = next;
|
---|
170 |
|
---|
171 | // Remove all entries in the free list from this block
|
---|
172 | ! if (prev_free != 0)
|
---|
173 | ! nextof(prev_free) = free;
|
---|
174 | else
|
---|
175 | ! this->first = free;
|
---|
176 |
|
---|
177 | // And release memory
|
---|
178 | UserAllocator::free(ptr.begin());
|
---|
179 | --- 380,389 ----
|
---|
180 | list = next;
|
---|
181 |
|
---|
182 | // Remove all entries in the free list from this block
|
---|
183 | ! if (prev_freeptr != 0)
|
---|
184 | ! nextof(prev_freeptr) = freeptr;
|
---|
185 | else
|
---|
186 | ! this->first = freeptr;
|
---|
187 |
|
---|
188 | // And release memory
|
---|
189 | UserAllocator::free(ptr.begin());
|
---|