Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Nov 2010
Offline Last Active Jun 08 2014 08:41 PM

Posts I've Made

In Topic: Index Buffer Object vs. Index Array

07 June 2013 - 06:43 AM

Sponji and mhagain are right, that was my question and thank you for your answers. As well as marcClintDion, thank you for your descriptive answer, and references(!). 

This was more of a simply a conceptual question since I noticed it could work both ways.

In Topic: Allocator crash after alloc/dealloc

01 January 2013 - 09:37 AM

Does this not strike you as being a little silly?:

		mMemory = new (std::nothrow) char[mMaxSize * mOffset];
		// mMemory = malloc(mMaxSize * mOffset);
		if (!mMemory)
			//Do something more informational here
			throw std::bad_alloc();
I mean why explicitly use nothrow only to ultimately end up replicating the throw behaviour?
The return is also pointless since it can never be reached.


I'm aware of this, thank you. This also wasn't what my post was about, the code originally had other behavior but in the interim of deciding how to refactor the code, I changed it (rather than deleting it and letting new throw the exception). As I said in the OP, it's a learning exercise, so if you have nothing worth while to contribute, please don't.


@Khatharr, Thank you for your suggestions, I actually wrote this a long time ago and didn't understand what I was doing( to an even greater extent than I do now xD). I'll try you suggestions and see where they take me. If I run into any problems I can't fix on my own, I'll find myself right back here in the forum.

In Topic: Allocator crash after alloc/dealloc

31 December 2012 - 07:48 PM

'ptr' does not point to itself. Even if it did this would not be correct, since the arg is a copy with the same value rather than the same pointer. You need to search out the pointer value manually.

virtual void dealloc(char* ptr, size_t = 0) {
MemChunk *pCurChunk = (MemChunk*) ((char*) ptr - sizeof(MemChunk));



You must have edited this out, but I looked into it and finally made sense of it. After looking it over, I realized that this line of code was going back 8 bytes from 'ptr' but my real intention was to basically subtract 8 [ sizeof (MemChunk* )* 2 ] from the actual address of the pointer. I _think_ I accomplished that, like this.

MemChunk *pCurChunk = (MemChunk*) reinterpret_cast<char*>(reinterpret_cast<ptrdiff_t>(ptr)
- static_cast<ptrdiff_t>(sizeof(MemChunk*) * 2));


Whether this fixed my problem is still yet to be tested extensively, but it passed the quick test I put together for it.


I also took your advice and added a data member to the MemChunk struct which does allow me to use an array index, making things a lot more readable. 


Lastly, I realized that the addresses from mFirst to mLast were descending, which was the opposite of what I wanted it to do (which accounts for the weird subtraction in the getPtr() function). To fix that, I made the loop that links the nodes together run backwards (from mMaxSize to 0). That allowed me to directly access the memory in the getPtr function the way I intended.

In Topic: Allocator crash after alloc/dealloc

31 December 2012 - 02:23 AM

destroy is defined in AllocBase, it simply calls the destructor of the object,


and yes the dealloc call is triggering the segfault, although it will work for a variable amount of times before causing a crash.

In Topic: A Shapians Tale

25 March 2012 - 04:42 PM

I don't feel like going to another site just to see a screenshot.

Here you are. I'll grab more when I can.

Posted ImagePosted ImagePosted Image

Posted Image