Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <new>
- constexpr unsigned long limit = 10000000; // 10MB
- char *memory[limit];
- unsigned long in_use_count = 0;
- void *alloc(unsigned long size)
- {
- if (in_use_count + size >= limit)
- throw std::bad_alloc();
- unsigned long ptr = in_use_count;
- in_use_count += size;
- return (void *)&memory[ptr];
- }
- void *operator new(unsigned long size)
- {
- return alloc(size);
- }
- void *operator new[](unsigned long size)
- {
- return alloc(size);
- }
- int main()
- {
- int *my_ints = new int[20];
- for (int i = 0; i < 20; i++) {
- my_ints[i] = i;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement