#include "PagedAllocator.h"
+#include <stdexcept>
+
using std::deque;
+using std::runtime_error;
+
namespace loader {
return chunk;
}
+unsigned int PagedAllocator::PageOf(void *ptrIn) const {
+ char *ptr = reinterpret_cast<char *>(ptrIn);
+ unsigned int counter = 0;
+ for (deque<char *>::const_iterator i(pages.begin()), end(pages.end()); i != end; ++i, ++counter) {
+ if (ptr < *i) continue;
+ if (*i < ptr) return counter;
+ }
+ throw runtime_error("PagedAllocator::PageOf");
+}
+
+unsigned int PagedAllocator::PageOffsetOf(void *ptrIn) const {
+ char *ptr = reinterpret_cast<char *>(ptrIn);
+ for (deque<char *>::const_iterator i(pages.begin()), end(pages.end()); i != end; ++i) {
+ if (ptr < *i) continue;
+ if (*i < ptr) return ptr - *i;
+ }
+ throw runtime_error("PagedAllocator::PageOffsetOf");
+}
+
unsigned int PagedAllocator::Free() const {
return pageSize - (head - CurrentPage());
}