App Hub
Sort Discussions: Previous Discussion Next Discussion
Page 2 of 2 (29 posts) < Previous 1 2

possible to have an array on stack, not in heap?

Last post 10/10/2008 4:28 AM by JasonD. 28 replies.
  • 10/10/2008 1:32 AM In reply to

    Re: possible to have an array on stack, not in heap?

    Ego:
    Firstly I'd double check that you're really optimising. Is this a bottleneck as identified by a profiler, or by inspection? This may sound like a dumb thing to say, but I wouldn't waste your time at this level of optimisation unless you've got a demonstrable bottleneck courtesy of a profiler.

    Ego, just to be clear, this function was responsible for take a full second -- that's 60 frames -- to create 17,000 particles, something that my 3.0 GHz PC can do in 1/60th of a second no problem.  So, I didn't need a profiler to know this was the bottleneck, as it was clear due to the slowdown of just that one particular instance in my game.

    However... I would LOVE to use a real profiler to find out what else is slowing my game down.  I've used the CLR Profiler 2.0, but I think that's just for things like GC and the like... it won't point out where floating point code is bringing the execution to a stand-stand, AFAIK.

  • 10/10/2008 1:43 AM In reply to

    Re: possible to have an array on stack, not in heap?

    Ego,

    Thanks for all your options.  :)  It is appreciated!

    I'll keep in mind that a small amount of garbage collection is probably not a bad thing.  I only got a few hiccups from GC when I was very stupidly allocating 1,000,000's of small classes to store a rectangle (it should have been a struct, so it was on the stack) over the course of a minute.  I almost barely noticed the GC handling all of that, so I'm sure even if I new'ed a 4 Color element array 60 times a second, it would be nothing for the GC to handle.  Right now, the GC isn't invoked at all during my game play, so I have a lot of room to work with.

    I could unroll the loop, but it seems more complex than what it's worth.  Thanks for the suggestion, though.

    Thanks for the info regarding how easy it is to do my own custom thread local storage.  Yes, all I have to do is allocate it myself and pass it into the threads, so they each have their own copy.  Simple.  :)

    A simple thread local storage array is definitely the answer, it's just too bad the code to do it wasn't as easy as it would be if the Xbox Compact .NET framework supported it like it does on the PC.

  • 10/10/2008 2:09 AM In reply to

    Re: possible to have an array on stack, not in heap?

    Glad I'm wasn't just waffling incomprehensibly :)

    I'm not sure if you're looking for an XBox or PC profiler. I suspect the former, in which case ignore the rest of this paragraph - but if the latter, I'd definitely recommend trying out ANTS Profiler 4. (Full disclosure: I have been in the past, though am not currently, affiliated with the makers. I just rather like this new version.) I've used it to pull out a few problems in PC-based XNA dabblings of my own, and there's a 14 day free trial.

    I assume you've pinned it down to a CPU rather than GPU issue. Lacking any further ability to profile the code, and assuming you haven't done already, which you probably have, I'd try changing the code peacemeal rather than a big bang rewrite if you want to find out where the problem is. Commenting code out a line at a time is so passe these days, but still. (Edit: rereading your post, you clearly have pinned it down already. Apologies.)

    More abstractly, it's a shame about ThreadStatic on the XBox - I'm guessing that ThreadStatic actually ends up using Windows' TlsAlloc(), TlsFree() etc. and there just isn't a handy OS-level equivalent on the XBox.

  • 10/10/2008 4:28 AM In reply to

    Re: possible to have an array on stack, not in heap?

    Ego,

    Yes, I am only really interested in a profiler for the Xbox 360, since that's where the floating point issues of it's Compact .NET framework come into play.

    Yes, it is a shame about ThreadStatic on the XBox... it was such as nice addition to C++ that MS added the __declspec(thread), as it just made it so easy to use.  Too bad we can't do this on the Xbox...

Page 2 of 2 (29 posts) < Previous 1 2 Previous Discussion Next Discussion