Jump to content

  • Log In with Google      Sign In   
  • Create Account

AlexB.hpp

Member Since 11 Oct 2012
Offline Last Active Aug 23 2013 03:35 AM

#5004897 [С++] Memory leak checker

Posted by AlexB.hpp on 28 November 2012 - 02:48 AM

Don't forget calloc() and realloc(). realloc() is always a fun one to deal with because depending on how you call it, it can also act like malloc() or free().

Thx for calloc don't even know about it.


#5004712 [С++] Memory leak checker

Posted by AlexB.hpp on 27 November 2012 - 04:42 PM

I've started working on simple and little class for C++ to check some memory leaks. I have made some work on it, but there is a lot of work to do. I'm planing to add cppunit, autoreconf, documentation, static class instread of global functions, different loggers.

Now it has:
shared library,
header with some funcs declarations,
makefile to build it via g++,
simple script to test it,
linux only but I'll port it to win after some researching.

I do it for my own project but I would like to share it with a great pleasure.

Now it looks like this
alexb leak_checker> ./run.sh
MEMORY LEAK! 0x8c1a008 main.cpp 5
MEMORY LEAK! 0x8c1a038 main.cpp 6

with such main:
#include <iostream>
#include "allocation_hooks.h"
int main(int argc, char** argv) {
  int* num = new int;
  num = new int[1];
  check_map();
}


Repo is here.

PS Warning it has some magic in it! ^_^


#5004235 Stuck on newbie project

Posted by AlexB.hpp on 26 November 2012 - 11:12 AM

AlexB.hpp:
I take it you´re joking? ...

Don't be mad about that... I didn't mean any stupid stuff. I wanted to said that you have a great possibility to make a nice game and take a lot of experience.

Some time I write/say totally strange things, but it's ok for me. That's how I start deep thinking.


#5004162 Stuck on newbie project

Posted by AlexB.hpp on 26 November 2012 - 03:45 AM

You need collision detector cauze bullets gets thought terrain. Actually there is a lot of possible improvements. Does your character can shot only horizontal ax? Are there any other types of weapons? What about some enemies? What about twitter or smth else in it? Does it have achievements?

---

Looks like my English still pretty bad if I couldn't talk what I want.


#5002741 30 Tips For Newbie Game Programmers

Posted by AlexB.hpp on 20 November 2012 - 02:08 PM

I've got nice link from 3D Game Engine Programming by Stefan Zerbst and Oliver Duvel to gamasutra.com.

Surfing it for a little I've got to a programmer blogs. And got it - 30 Tips For Newbie Game Programmers by Emrah Ozer.

I want to talk a little about 8th tip:

If you're developing your own game -please I beg you- don't make a clone game. Nobody needs a another bubble game. Clone game development causes you to not to learn the game design iteration process.


I think it's really important for us, I'm talking about novices in gamedev which are looking for idea to realize.
There is no need to realize ping-pong, asteroids, breakout and other crap, being implemented so many times...

For those who don't know about ludum dare.
So as a source of ideas I want to show you ludum dare contest. There is no prizes or anything, but there you can find really interesting in gamedev people which can give you a nice feedback to make you game better. So read about this contest and take a part in next one.


#5002075 Best OpenGL books for beginners (C++)

Posted by AlexB.hpp on 18 November 2012 - 11:37 AM

About dates - it's ok. OpenGL don't changes too fast. Anyway this 2 books awesome starting point in OpenGL learning. I've read first one.

Look at this one - OpenGL SuperBible. It's brilliant. I'm reading it now and I like it so much.


#5002072 Impotant! Books to start learning video game programming ! I need it...

Posted by AlexB.hpp on 18 November 2012 - 11:09 AM


Im not sure if this was said already but a good book, that i personally learned c++ from, is called beginning c++ through game development. Its cheap and very easy to understand. And when it says through game development, its using simple text games as examples for learning c++. As many will say to stay away from c++ if you are just learning how to program since it is complicated, i say go for it. I learned c++ first, and it was challenging, and i don't recommend it, but it can be done.

http://www.amazon.ca...6851&amp;#38;sr=8-2

Also, there is c++11 out, and i haven't looked into it, and i really don't want to right now, but maybe you should look for something that explains that. Now don't quote me on anything, but c++11 is the new version of c++ and people will probably start moving towards that.


thanks, i am using c++ which come with visual studio 2012, if m correct it is c++11

Actually it looks like VS 2012 has default support of cxx11 (just another one way to write c++11).

Hm... I suggest next book as base of programming - Ivor Horton's Beginning Visual C++ 2012. This book is really nice to a novice showing all basic stuff: variables, loops and so on. But I'm warning you - C++ is difficult. It's much complicated than C# and Java, because it haven't memory manager as it's in Java and C#.

Did you make a final decision? Probably it would be better to you to start with C# and XNA? It's allow you to do some simple games in near future.


#5001710 How should I tackle programming

Posted by AlexB.hpp on 17 November 2012 - 01:54 AM

To protect the TS! I'd spend on C++ about 3.5 years and still learning it.
GameDev programming is just another branch in programming. So you should learn it as another one. And if you start learning it on 1st year of learning the language, then you will more skilled in it on 2nd, 3rd year.

I wish to TS a good luck and be patient.

PS You do need a challenges to learn anything. There is no other way.


#4996083 OpenGL Rendering over SDL

Posted by AlexB.hpp on 31 October 2012 - 11:32 PM

That's very true. I wanted to explore the functionality of both, but for now I will only use SDL. I think SDL provides a more straight forward approach. I haven't been able to find a really good tutorial for OpenAL for beginners. I'm going to adjust the code later and see what you guys think about it. I am going to use only SDL in the first case. Also any advice on whether I should use SDL or glut/OpenAL? Which would be more practical for creating an rpg game?

Use SDL for your projects. It provides set of completed tools to create nice looking games.


#4991588 Good C++11 resources for advanced programmer

Posted by AlexB.hpp on 18 October 2012 - 04:56 PM

First of all look at this link, then you can read all interesting you proposals by clicking it.

What about books... It will be written sometime but probably after > 0.5 year. IMHO.

Read some cool guy's blogs. Just like that one is


#4991540 Is it acceptable to call a destructor?

Posted by AlexB.hpp on 18 October 2012 - 02:31 PM

Ofc you can use it that way. It will looks smth like this:
We run loop on an array of some objects to check some abstract requirement.
#include <stdio.h>
#include <list>
class A {
public:
  A() {
	printf("A:constructor.\n");
  }
  ~A() {
	printf("A:destructor.\n");
  }
};
int main() {
  std::list<A*> objects;
  printf("Allocate 10 objects of A\n");
  for (int i = 0; i < 10; i++)
	objects.push_back(new A());

  printf("Time to die\n");
  int list_size = objects.size();
  for (int i = 0; i < list_size; i++) {
	A* deadbeef = *(objects.begin());
	objects.erase(objects.begin());
	delete deadbeef;
  }
  printf("Elements in list: %d\n", objects.size());
}

Output:
Allocate 10 objects of A
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
Time to die
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
Elements in list: 0

But this is now clever 'cause memory allocation is kinda slow operation. Much better if we will save memory for such type of object and use it letter.

#include <stdio.h>
#include <list>
class A {
public:
  A() {
	printf("A:constructor.\n");
  }
  ~A() {
	printf("A:destructor.\n");
  }
  void Clear() {
  }
};
class AAlloc {
  std::list<A*> _cache;
public:
  A* Alloc() {
	if (!_cache.empty()) {
	  A* deadbeef = _cache.front();
	  _cache.erase(_cache.begin());
	  deadbeef->Clear();
	  return deadbeef;
	}
	return new A();
  }
  void Dealloc(A* obj) {
	_cache.push_back(obj);
  }
  ~AAlloc() {
	std::list<A*>::iterator itr = _cache.begin();
	for ( ; itr != _cache.end(); ++itr) {
	  delete *itr;
	}
  }
};
int main() {
  std::list<A*> objects;
  AAlloc allocator;
  printf("Allocate 10 objects of A\n");
  for (int i = 0; i < 10; i++)
	objects.push_back(allocator.Alloc());

  printf("Time to die\n");
  {
	std::list<A*>::iterator itr = objects.begin();
	for ( ; itr != objects.end(); ++itr) {
	  allocator.Dealloc(*itr);
	}
	objects.clear();
  }
  printf("One more allocation of 10 objects\n");
  for (int i = 0; i < 10; i++)
	objects.push_back(allocator.Alloc());
  printf("IT\'S A GOOD DAY TO DIE!\n");
  {
	std::list<A*>::iterator itr = objects.begin();
	for ( ; itr != objects.end(); ++itr) {
	  allocator.Dealloc(*itr);
	}
	objects.clear();
  }
  printf("Elements in list: %d\n", objects.size());
}


New output:
Allocate 10 objects of A
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
A:constructor.
Time to die
One more allocation of 10 objects
IT IS A GOOD DAY TO DIE!
Elements in list: 0
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.
A:destructor.

It's maybe looks pretty tricky but the main reason is speed up application.


#4990305 What Do You Guys Think of How I Programmed This?

Posted by AlexB.hpp on 15 October 2012 - 02:12 AM

AlexB.hpp, considering your new to the forum I'm not going to get mad at you, but who are you to be talking like you're an expert in C++? It doesn't matter if pointers are more flexible then references, I don't need pointers and I don't plan to use their harder to understand syntax. Also, you should probably realize I AM USING A LIBRARY CALLED SFML AND OMG I'M USING BOUNDING BOX COLLISION. That's why I can't "refactor" my code, and that's probably why you don't understand this:

LogicBall->GetCollision().Intersects(LogicBoard[index]->GetTop())

If you actually used SFML you would know what was going on. You also just signed up for the forum, so I suggest you stop telling people in the beginners
section that their code is:

this if is freaking terrible


I'm in the beginners section, do you expect "your" quality code.(That's considering your an actual developer, which I doubt you are.)

I'm saying that if Collision(A bounding box rectangle) intersects one of my blocks I set that block to being hit. If you knew what you were talking about you might understand that.

BUT,

Your interface Manager idea is smart, and I might implement it later. Thank you for your input, just please be less harsh on people in the beginners section.


Sozz dude, looks like I was a little bit mean.

I'm not an expert but I'm trying to get some experience too. So that's why I wanna give you a little review.
Would you agree if guys will give you some feedbacks on your code to improve it. Your code looks really difficult to understand.

Did you just begin or not, it doesn't matter, 'cause you HAVE to write good code.

Let me tell what I call good code. Good code - when you send it to another programmer with enough skill, he can understand and modify it after few hours of reading.
Sooo that's why I said that that some part of your code freak me out. But ofc your code can be OK.

My suggestion - keep dev it, 'cause you've got nice feedback on it.


PARTNERS