Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Memory management trickery with arrays
- /// the first particle in the linked list
- Particle* start=0;
- /// the next free particle
- Particle* last=0;
- /// the end of the memory allocation
- Particle* end=0;
- void SetSize(unsigned int size) {
- // delete any previous data
- delete [] start;
- // allocate new particles
- last = start = new Particle[size];
- // set end
- end = start+size;
- }
- void AddOne() {
- // if we have no more memory left for any particles, ignore
- // the request to creat one.
- if (!IsFull()) {
- *last = Particle();
- ++last;
- }
- }
- void EraseOne(Particle* p) {
- if (!IsEmpty()) {
- *p = *(--last);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment