Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 12 Oct 2004
Offline Last Active Today, 09:06 AM

Posts I've Made

In Topic: Returning by value is inevitable?

26 April 2016 - 12:08 PM

Anyone care to explain what is wrong with the static variable solution? I've used this for years and always thought it was a convenient and fast solution.


It's not faster nor more convenient than RVO. Also, it breaks on multi-threading.

In Topic: Noob pointer question

24 April 2016 - 01:07 PM

There are some things you will have to lookup and take your time to get a good understanding of. I'll try to give a short version of that in this post, but it's by no means complete, but I hope it's enough to send you off in the right direction.


Using new and delete in C++ are ways of allocating and deallocating memory. It's true that new returns a pointer and that delete takes a pointer as input, but there is no such thing as deleting a pointer.


What new does is basically request some memory (the size of the given type) and returns something that allows you to access that part of memory, a pointer. A pointer is nothing more than some value indicating a location in memory. If you view your memory as a giant array of bytes, a pointer would just be an index. When this memory is allocated, it'll stay that way until you instruct the computer to deallocate it. Unlike JavaScript, you have to manually manage this memory. You can deallocate memory by calling delete and passing it the pointer you got from new.


So why doesn't it work in your second case? Well there are two types of memory allocation, one is for static allocations and the other for dynamic allocations. The stack is used for static allocation and the heap is for used for dynamic allocations. The stack is basically some memory allocated beforehand, which requires no work from your side, that's used for things like local variables and function arguments. It's called the stack because it's literally how it works. Things are put on top in some order and in then they're taken off in the reverse order. In code that means that at the beginning of a scope (e.g. a function) the necessary space is reserved, and at the end of the scope (e.g. exiting a function) that reservation is lifted. Everything about this is automatic, but the stack has limited size and one other limitation; what if you want to retain the memory outside of the scope? This can't be managed automatically by the stack, it only knows how to put stuff on and then take it off again, it wouldn't be able to know when that part of memory will be free for use again. This is where heap memory comes in, it's memory that you can manually manage and is practically unlimited in size. This manual management is done with new and delete.


In your second example, you are trying to delete memory from the stack, but delete is meant for heap allocations.

In Topic: Should I use multithreading for sending messages?

20 April 2016 - 03:20 PM

What would you recommend for a server that's running multiple standalone rooms/arenas (no transfer of users between rooms)? In C# I'm envisioning a system that runs each arena on its own thread and has a separate dedicated network I/O thread. C# provides a built-in thread-safe ConcurrentQueue collection that would be useful for passing messages back and forth.


I'm wondering if a single network I/O thread (handling UDP traffic for all of the arenas, and possibly a second TCP connection for RCON) would be a bottleneck, or if I should run each arena with its own port and have it do its own I/O. If I'm running on a 1-2 core VPS, threading might also be unnecessary overhead. I could run everything on the main thread (recv, update arena 1, update arena 2, update arena 3, ..., send) as well, but that seems a little brittle.


Generally you want the amount of threads you have match the amount of cores you have available, or cores minus one. In the case you describe you'd evenly divide the amount of arenas over the amount of threads you have. There's no need for thread safe queues if there's no communication taking place between the arenas. You can do away with any complexity by having a single socket per thread that's shared among all arenas on that thread.

In Topic: Is there a set of local "basis" vectors in a matrix?

13 April 2016 - 04:53 AM

To elaborate a bit on what Frob said: the basis vectors in your matrix that are not canonical are all unit vectors and they're all perpendicular to each other. You can view them as rotated standard basis.


I'm guessing you're looking for the following: you have matrices A and B, you need a matrix C so that when A*C = B. Is that a correct assessment? If so, then C = A^-1 * B, where A^-1 is the inverse matrix of A.

In Topic: Is there a set of local "basis" vectors in a matrix?

12 April 2016 - 09:33 PM

There are a lot of questions in there, but it's not very clear to me what you're asking or what your problem is. What do you mean when you use the term canonical?