aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-09-11 00:44:28 +0000
committerlloyd <[email protected]>2006-09-11 00:44:28 +0000
commit31170c2210d98c2ea8f3fac56ff5f31e27f741af (patch)
treeb43349234dfb36ae0b6e3ea97923e7f5f52eb06e /include
parenta563159b999eea2fee0ea94d0baaea06df0ca1df (diff)
Correctly deal with allocators added post-initialization. In particular,
handle the case where an allocator is added that has the same name as one already registered. Flush the cached allocator pointer when the default is changed. Mark comparison operations in Pooling_Allocator::Memory_Block as inline; this seems to help the STL sort and binary search algorithms tremendously.
Diffstat (limited to 'include')
-rw-r--r--include/allocate.h3
-rw-r--r--include/libstate.h4
-rw-r--r--include/mem_pool.h4
-rw-r--r--include/secmem.h4
4 files changed, 9 insertions, 6 deletions
diff --git a/include/allocate.h b/include/allocate.h
index d30e4e0bc..6472924d5 100644
--- a/include/allocate.h
+++ b/include/allocate.h
@@ -17,6 +17,8 @@ namespace Botan {
class Allocator
{
public:
+ static Allocator* get(bool);
+
virtual void* allocate(u32bit) = 0;
virtual void deallocate(void*, u32bit) = 0;
@@ -31,7 +33,6 @@ class Allocator
/*************************************************
* Get an allocator *
*************************************************/
-Allocator* get_allocator(const std::string& = "");
}
diff --git a/include/libstate.h b/include/libstate.h
index 5bfb4018d..ece05609a 100644
--- a/include/libstate.h
+++ b/include/libstate.h
@@ -31,7 +31,8 @@ class Library_State
friend class Engine_Iterator;
Allocator* get_allocator(const std::string& = "") const;
- void add_allocator(Allocator*, bool = false);
+ void add_allocator(Allocator*);
+ void set_default_allocator(const std::string&) const;
void set_prng(RandomNumberGenerator*);
void randomize(byte[], u32bit);
@@ -78,6 +79,7 @@ class Library_State
class Charset_Transcoder* transcoder;
RandomNumberGenerator* rng;
+ std::vector<Allocator*> allocators;
std::vector<EntropySource*> entropy_sources;
std::vector<class Engine*> engines;
};
diff --git a/include/mem_pool.h b/include/mem_pool.h
index 59599d65c..e365cd29d 100644
--- a/include/mem_pool.h
+++ b/include/mem_pool.h
@@ -46,9 +46,9 @@ class Pooling_Allocator : public Allocator
byte* alloc(u32bit) throw();
void free(void*, u32bit) throw();
- bool cmp_mem(const void* x) const { return (*this) < x; }
bool operator<(const void*) const;
- bool operator<(const Memory_Block&) const;
+ bool operator<(const Memory_Block& other) const
+ { return (buffer < other.buffer); }
private:
typedef u64bit bitmap_type;
static const u32bit BITMAP_SIZE = 8 * sizeof(bitmap_type);
diff --git a/include/secmem.h b/include/secmem.h
index 84c821ec7..7873c8b1f 100644
--- a/include/secmem.h
+++ b/include/secmem.h
@@ -75,8 +75,8 @@ class MemoryRegion
set(copy.buf, copy.used);
}
- void init(bool lock, u32bit size = 0)
- { alloc = get_allocator(lock ? "" : "malloc"); create(size); }
+ void init(bool locking, u32bit size = 0)
+ { alloc = Allocator::get(locking); create(size); }
private:
T* allocate(u32bit n) const { return (T*)alloc->allocate(sizeof(T)*n); }
void deallocate(T* p, u32bit n) const