Last change
on this file was
80,
checked in by Sam Hocevar, 15 years ago
|
- Adding the Golgotha source code. Not sure what's going to be interesting
in there, but since it's all public domain, there's certainly stuff to
pick up.
|
File size:
1.8 KB
|
Line | |
---|
1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "memory/growheap.hh"
|
---|
10 | #include "error/error.hh"
|
---|
11 |
|
---|
12 | i4_grow_heap_class::i4_grow_heap_class(w32 initial_size, w32 grow_increment)
|
---|
13 | //{{{
|
---|
14 | {
|
---|
15 | increment=grow_increment;
|
---|
16 |
|
---|
17 | if (initial_size)
|
---|
18 | {
|
---|
19 | heap *h=new heap(initial_size,"initial grow heap");
|
---|
20 | list.insert(*h);
|
---|
21 | current_size=initial_size;
|
---|
22 | current_offset=0;
|
---|
23 | }
|
---|
24 | else
|
---|
25 | {
|
---|
26 | current_size=0;
|
---|
27 | current_offset=0;
|
---|
28 | }
|
---|
29 | }
|
---|
30 | //}}}
|
---|
31 |
|
---|
32 |
|
---|
33 | void *i4_grow_heap_class::malloc(w32 size, char *description)
|
---|
34 | //{{{
|
---|
35 | // description not used right now
|
---|
36 | {
|
---|
37 | if (size==0)
|
---|
38 | return 0;
|
---|
39 |
|
---|
40 | if (current_offset+size<current_size)
|
---|
41 | {
|
---|
42 | void *ret=(void *)(((w8 *)list.begin()->data)+current_offset);
|
---|
43 | current_offset+=size;
|
---|
44 | return ret;
|
---|
45 | } else
|
---|
46 | {
|
---|
47 | if (size>increment)
|
---|
48 | i4_error("grow heap param problem");
|
---|
49 |
|
---|
50 | heap *h=new heap(increment,"grow heap");
|
---|
51 | list.insert(*h);
|
---|
52 | current_size=increment;
|
---|
53 | current_offset=0;
|
---|
54 | return malloc(size,description);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | //}}}
|
---|
58 |
|
---|
59 |
|
---|
60 | void i4_grow_heap_class::clear()
|
---|
61 | //{{{
|
---|
62 | {
|
---|
63 | heap_iter p = list.begin();
|
---|
64 | heap_iter q(p);
|
---|
65 |
|
---|
66 | current_offset=0;
|
---|
67 |
|
---|
68 | ++p;
|
---|
69 |
|
---|
70 | while (p != list.end())
|
---|
71 | {
|
---|
72 | list.erase_after(q);
|
---|
73 | delete &*p;
|
---|
74 | p = q;
|
---|
75 | ++p;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | }
|
---|
80 | //}}}
|
---|
81 |
|
---|
82 |
|
---|
83 | //{{{ Emacs Locals
|
---|
84 | // Local Variables:
|
---|
85 | // folded-file: t
|
---|
86 | // End:
|
---|
87 | //}}}
|
---|
88 |
|
---|
89 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.