align16New.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
align16New.cc
Go to the documentation of this file.
1 /* align16New.cc
2 */
3 #include "osl/misc/align16New.h"
4 #include <cassert>
5 #include <cstdlib>
6
7 void * osl::misc::Align16New::operator new(size_t size)
8 {
9 char *ptr = ::new char[size+Alignment];
10 for (int i=0; i<Alignment; ++i) {
11 if (reinterpret_cast<unsigned long>(ptr + i + 1) % Alignment == 0) {
12 *(ptr + i) = i + 1;
13 // std::cerr << ">> " << (long)ptr << " => " << (long)(ptr + i + 1) << "\n";
14 return ptr + i + 1;
15 }
16 }
17 assert(0);
18 abort();
19 }
20
21 void * osl::misc::Align16New::operator new[](size_t size)
22 {
23 return operator new(size);
24 }
25
26 void osl::misc::Align16New::operator delete(void *ptr, size_t /*size*/)
27 {
28 char *p = static_cast<char*>(ptr);
29 int offset = *(p-1);
30 ::delete(p - offset);
31 // std::cerr << "<< " << (long)p << " => " << (long)(p - offset) << "\n";
32 }
33
34 void osl::misc::Align16New::operator delete[](void *ptr, size_t size)
35 {
36 return operator delete(ptr, size);
37 }
38
39 // ;;; Local Variables:
40 // ;;; mode:c++
41 // ;;; c-basic-offset:2
42 // ;;; End: