Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About jamesd128

  • Rank
  1. I'm not basing this question on a current problem or anything. It's just that more often than not when I'm using an array, I have to insert the values myself and it just seems like a waste to have them initialized to 0 then reinitialized to whatever I'm using. I was asking so that if at some point in the future I write a function which gets executed many times per second which requires the use of a local array, it seems to me a useless O(n) operation would in fact slow performance.
  2. Well, yes I would expect them to contain garbage like c++. How is zeroing everything not a performance issue? Doesn't zeroing everything take O(n) time, whereas just setting aside the memory for the array shouldn't take that long?
  3. So in Java and C# when you create an array like int[] ar = new int[10]; It automatically initializes each element to 0. What I'm wondering is, can I get space for an array without initializing to 0, hopefully making the line execute faster?
  4. jamesd128

    Java: BFS implementation question

    Ok HashSet sounds right. So from what I understand HashMaps are <key,value> pairs, HashSets are just values. However, the javadocs say this about HashSets "This class implements the Set interface, backed by a hash table (actually a HashMap instance)" which makes me wonder, whats the value part of that HashMap instance that a HashSet uses.
  5. In BFS I need to keep track of whether or not a node has been visited. I therefore want to put all visited nodes in a hash map so I can tell in O(1) time whether or not something has been visited (not using a bool visited data member). If the node is the key, then there's no point in wasting space with a value since I just want to check if the entry exists. So my question is, is there some sort of hash map that basically consists of only the key with no value?
  6. Here's what I want to do in java code: class A{ int varName; A(int varName){ this.varName = varName; } } I just want to use the same variable name for both the function parameter and member variable, but still be able to access the member variable. Obviously I can just change the name to m_varName or something, but I don't want to. this.varName = varName; doesn't work in c++, is there an equivalent?
  7. Ah that fixes it, didn't realize you couldn't call other constructors like that in c++. If you know though, why exactly does that "differs in levels of indirection" error come up?
  8. I'm just having trouble understanding whats going on here. When I try to compile this code I get the following error error C2040: 'cfg' : 'Wrapper' differs in levels of indirection from 'Cfg *' Could someone please explain what's happening? class Cfg{ int stuff; }; class Wrapper{ public: Wrapper(Cfg *cfg){} Wrapper(){ Cfg *cfg = new Cfg(); Wrapper(cfg); } };
  9. jamesd128

    c++ hash_map help

    ... what the hell that was the FIRST thing I tried and it didn't work so I spent like an hour trying different things. now I try it again and it works this time. well thanks for the advice
  10. jamesd128

    c++ hash_map help

    Could someone tell me the right way to do this in VS 2008? stdext::hash_map <const char*, Node*> lookup; string s = "test"; lookup[s.c_str()] = new Node; string s2 = "test"; cout<<lookup[s2.c_str()]->number<<endl; // gets access violation exception I've looked online and found a couple ways to make hash_maps take string keys but always get some compilation error.
  11. I don't believe WiX has any such restrictions. I'm definitely not going to hire a lawyer since to be honest I think the odds of the game being accepted by a publisher, even a small one, are remote at best and will more likely be distributing it freely. You mentioned a copywrite notice or NDA, are there general licenses like that on the internet that I can just stick onto my installer? Lacking that, is it a terrible idea to just send them an installer with no license attached to it?
  12. I have a game that I would like to send to a small games publisher to see if they like it. I'm using WiX to make an installer, but the default license it puts on the installer gives the recipient the right to redistribute or basically do whatever they want with the software I'm giving them. Is there some generic demo license that I should use instead?
  13. jamesd128

    Why port forwarding?

    So I have a general understand of how NATs work and in why port forwarding is needed, what I don't understand is why it's needed in only certain cases. If I set up a TCP listening socket so someone can connect to me, I have to port forward the port that socket is listening on. Once someone connects to me, that socket spawns another socket for the actual communication to take place and assigns it a random port. My question is why does the listening socket's port need to be port forwarded, but the random port it creates for the communication socket does not need any port forwarding?
  14. Actually the only reason I'm doing this is to avoid NAT issues. The TCP/IP option of my game uses fully connected sockets. If the host and another player are behind a NAT, the host needs to be able to tell the third player how to connect to the other person behind the NAT. To do this I require all players who are joining my game from within my network to provide their external IP (by querying whatismyip). I can then pass that external IP to the player who is joining from outside the network. The points is I need to know if they are from my network to see if I should require them to provide an external IP.
  15. Nevermind that didn't work as intended, here's a new version: IPAddress clientIPAddr = IPAddress.Parse(socket.RemoteEndPoint.ToString().Split(new char[1] { ':' })[0]); IPAddress hostLocalIPAddr = IPAddress.Parse(socket.LocalEndPoint.ToString().Split(new char[1] { ':' })[0]); bool onSameNetwork = true; foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces()) { if (f.OperationalStatus == OperationalStatus.Up) { IPInterfaceProperties ipInterface = f.GetIPProperties(); foreach (UnicastIPAddressInformation unicastAddress in ipInterface.UnicastAddresses) { if (unicastAddress.IPv4Mask != null && unicastAddress.IPv4Mask.ToString() != "") { String[] parts = unicastAddress.IPv4Mask.ToString().Split(new char[1] { '.' }); int[] subnetMask = new int[4] { Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2]), Int32.Parse(parts[3]) }; parts = clientIPAddr.ToString().Split(new char[1] { '.' }); int[] clientAddr = new int[4] { Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2]), Int32.Parse(parts[3]) }; parts = hostLocalIPAddr.ToString().Split(new char[1] { '.' }); int[] hostAddr = new int[4] { Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2]), Int32.Parse(parts[3]) }; for (int i = 0; i < 4; i++) { if ((clientAddr & subnetMask) != (hostAddr & subnetMask)) onSameNetwork = false; } } } } }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!