Jun
25
2008
0

C++ 0x Standard

I was reading through the new C++ Standard today, needing a break from the Massively Multiplayer Game Development book I”ve been reading. Some very nice features are being added with the new standard, such as Lambda functions, initializer lists, and finally hash tables to the Standard Template Library.

C++ 0x Wikipedia Article

Written by Kaluriel in: Code | Tags:
Jun
23
2008
0

Const Correctness

Whilst idling in IRC and working on an application, and reading a great book I found in the library (Object Orientated Game Development – from what I’ve read from other places, this one has the best descriptions and examples I’ve seen. Though I haven’t read that many, so there may be better.) I came by some C++ links that are helpful.

The Top 20 C++ Tips of All Time

C++ Const Correctness

I’ve always wondered the difference between “const int *pointer” and “const int * const pointer”, the second link gave insight. Not that it matters, I”ve been using it correctly since I started.

Written by Kaluriel in: Code | Tags: ,
Jun
20
2008
0

Site Bugs

Just noticed a few bugs in the website, pages appearing blank, etc. Will try to get around to fixing them soon

Written by Kaluriel in: General |
Jun
08
2008
0

Allocating on the Stack

While looking at various websites about dealing with memory fragmentation, I came by another useful function that I didn’t know about called alloca(). This function allocates memory on the stack, and so does not need to be freed, and only exists in the scope that it is in.

Here is an example.

// --- [ includes ] -------------------------------------------
//
#include <alloca.h>
#include <string.h>
#include <stdio.h>

// --- [ entry point ] ----------------------------------------
//
void main()
{
char * pTestText = static_cast<char *>( alloca( 100 ) );

strncpy( pTestText, "Testing :)\n", 100 );

printf( pTestText );
}

The alloca() function works just like malloc(), only of course returning memory that is on the stack. This can be potentially bad for memory stomping, since pointers in the local scope could be altered if you go outside of the stack allocated.

I’m trying to always use the version of strings that are safe, since they has the potential to go wrong if a string doesn’t have a null character.

Written by Kaluriel in: Code | Tags: , ,

Theme: TheBuckmaker.com Blog Themes | The best Webhosting Plans, Eigenes Internet Radio