• Advertisement

• ### Popular Now

• 13
• 18
• 19
• 27
• 10
• Advertisement
• ### Similar Content

• Hi everyone! I'm currently working on a series of books about 2D Shader Development.

The idea is to synthesize a bunch of techniques that are specifically useful for 2D, even if they work on 3D as well.

I released the first book last week. It's 4.99 on Amazon or free on the series website, https://www.2dshaders.com

This is an independent initiative, I don't work for any publisher whatsoever. The contents of the books are the result of a 4-year span where I started teaching this in Argentina and USA, always making the workshop better. Now I'm expanding it to make more sense in book form.

I'd love to hear your opinions on the idea and if you get the book let me know what you think.

By the way, the examples are in Unity, but the concepts from the book should be easily transferable to any graphics api/engine.

Hope you like it!

• While looking out for that pesky Terrator, our little alien is doing a bit of relaxed mining down on the new gas planet "Lelantos" this weekend....
#gamedev #indiedev #madewithunity #screenshotsaturday

• I have a native iOS game (objective c, XCode build) which I am considering to port to other platforms.
Core gameplay is based on solely on geographical maps, and custom drawing over maps. It also has Core Data. This part is complete in development.
What is not done yet is: monetization, gamification (leaderboards, challenges) and multiplayer functionality.
As I think more about it, I am tempted to think if this is the right time to move to a cross platform tool such as Unity. But before dedicating time to port my 5 years side-project effort in Objective C, I really want to know if its worth it.
- Does Unity support such plugins / assets that will fulfill all my above requirements?
- Unity Personal seems to have only 20 concurrent users - is it too costly scaling if I decide for extending to web and android platforms?
- What is the general workflow involved in publishing to iOS, Android, PC, and web platforms while using Unity? I mean to ask about various points of signing stuff, paying fees and getting certified.
- How long will it really take to port my entire Objective C project into Unity? I am somewhat familiar with C# but I am finding it hard fidgeting with Unity IDE as lot of things are focused around FPS and 3D while my game is still 2d - not much action involved. I seem bit overwhelmed by the list of features I see there. All in all, I do not want to lose my momentum while still making sure its portable to everywhere.
- Any assets I could use (for free to try basis in debug) that are relevant for my game?
- Last but not the least, are there any costs that I need to be paying upfront to Unity, for using it (apart from their monthly subscription model)? I don't understand their costing for multiplayer in conjunction with their subscription fees - if someone could kindly elaborate.
Thanks in advance for your time reading a newbie
• By GytisDev
Hello,
me and few friends are developing simple city building game with unity for a school project, think something like Banished but much simpler. I was tasked to create the path-finding for the game so I mostly followed this tutorial series up to episode 5. Then we created simple working system for cutting trees. The problem is that the path-finding is working like 90% of the time, then it get stuck randomly then there's clearly a way to the objective (tree). I tried looking for some pattern when it happens but can't find anything. So basically I need any tips for how I should approach this problem.
Use this image to visualize the problem.
• By aymen
please any know how can i' calculate the centroid from any number vertices
• Advertisement
• Advertisement

# Unity Critique my memory tracker

This topic is 4014 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Until we get a Peer Review Forum, this can go here [smile] Anyway, I've written a memory manager which is pretty unobtrusive. It doesn't require macro hackery like MMGR, it tracks STL allocations, it works in x64, and is thread safe. And it gives the file, line number and function name of allocations. On the down side, it only works in debug builds, only on Windows, it's probably slow, and I don't like the stack walking code very much, it seems a bit hacky. It doesn't currently have any support for breaking on allocations since I haven't needed that support, but it should be easy enough to understand and modify. So here's the source code: PMemory.h, PMemory.cpp. The source is a little long to post here on a [ source ] tag, but the links are straight to the .cpp and .h files. It won't compile straight off, there's 3 changes you'll need to make.
1. #define USE_MMGR in your peoject settings, or remove all references to USE_MMGR
2. Remove the #include of EMemory.h
3. Remove the Assert() calls, or implement your own Assert() macro
The stack walking code "works on my machine", you might need to change the number of frames to walk on your own machines. Anyway, I'd be glad to hear any comments / suggestions / insults etc [smile] Cheers, Steve

#### Share this post

##### Share on other sites
Advertisement
I've just built it into my project, I'll give some more feedback once I give it a bit more use.

#### Share this post

##### Share on other sites
I would suggest that before you write your own memory management tools, you get familiar with what the development environment you're using already provides. If you're using DevStudio on Windows, then take a look at these articles about the debug heap. There's a huge amount of information available about memory usage. From personal experiance, I've found I've never needed any additional memory diagnostics to find problems.

Skizz

#### Share this post

##### Share on other sites
Quote:
 Original post by SkizzI would suggest that before you write your own memory management tools, you get familiar with what the development environment you're using already provides. If you're using DevStudio on Windows, then take a look at these articles about the debug heap. There's a huge amount of information available about memory usage. From personal experiance, I've found I've never needed any additional memory diagnostics to find problems.Skizz
I've skimmed over that before, although the last time I tried it, it didn't tell me the file:line or function of the allocation. Another thing you could do with my allocator, is store a full call stack, or at least several frames, that would allow you to more precisely find where leaks are comming from (E.g. STL containers).

#### Share this post

##### Share on other sites
Although file::line information might be useful to find the location of a leak, for example, in many instances it's not enough:
for (int i = 0; i < 100000 ; ++i){  // do something that allocates memory}

How would file::line help if iteration 45623 leaks memory but the rest don't? Using the _CrtSetDbgFlag function to set the _CRTDBG_LEAK_CHECK_DF flag produces a list of all the leaky memory in DevStudio's output window when the program exits. The important field here is the allocation number (in '{}'s IIRC). You can then use _CrtSetBreakAlloc to specify a break point for that allocation request. So, your code would be:
void main (args){   // set _CRTDBG_LEAK_CHECK_DF   if (there's an argument)   {      _CrtSetBreakAlloc (atoi (arg));   }   // rest of program}

and you would do the following:
  1) run program  2) if no leaks, end  3) get allocation number  4) run program with allocation number  5) program breaks to debugger when allocation made

Now, this is far better than just file::line information as it not only gives you the location but the context as well and the ability to debug and poke around the system.

Skizz

#### Share this post

##### Share on other sites
Breaking on an allocation ID is trivial to do, in fact the code is already there in the .cpp, there's just no function to set the break on alloc number [smile]
Breaking on an alloc ID only helps if your program allocates memory the exact same way each run. Admittedly, you'd try to do this anyway if you were tracking a memory leak, but there are many cases where it's not possible, such as the leak occuring at some allocation during the game. You'd have to run the game in the exact same way (including resetting all RNGs to the same value and ensuring the user input happens on the same frames, etc) to have the alloc ID alone be of any use.

Every other memory manager I've looked at (Although I haven't looked at many) either doesn't give you file and line information, or uses macro hackery to get you it, which breaks in some cases (E.g. MMGR using member operator new).

#### Share this post

##### Share on other sites
You're right, allocation ID does require consistent memory allocation and that is the main drawback to that method.

Just out of interest, what's the overhead of walking the stack and getting the caller location? It has to be said that the macro method for getting allocation location has very minimal overhead and is more portable (if that's important) but does suffer from having to code differently (i.e. not use 'new' directly).

Skizz

#### Share this post

##### Share on other sites
• __PMEMORY_H__. Reserved symbol. Evil (Steve).

• You seem to be using std namespace symbols in headers without namespace prefixes. I hope you don't have a using namespace std; in a header. That would just be Evil (Steve).

• Hungarian Notation. Ugh.

• Varargs. Ugh. Yes, I realise you're using it to avoid recursive calls to the memory manager, but still Ugh.

• Your operator new([])s don't follow the standard on allocation failure. You should loop, trying to allocate each time and, if failing to allocate either call the currently installed new_handler (if there is one) and loop again or throw std::bad_alloc if there is no currently installed new_handler.

• I'm pretty sure local static variables are not thread-safe.

• Your returned memory is not guaranteed to satisfy alignment requirements.

• It's possible that IMAGEHLP_LINE64::FileName is a pointer into the executables debug symbols, in which case you can just store the pointer rather than keeping an oversized buffer and copying the string yourself.
All in all, it looks pretty good. I've tried writing a similar implementation myself, but walking the stack manually (and hooking in to gcc's debug symbols). It works fairly well, although these days I manually allocate memory so infrequently I find a full-blown memory manager to be a bit over-the-top.

Σnigma

#### Share this post

##### Share on other sites

• Advertisement