Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 Jan 2011
Offline Last Active Oct 21 2014 11:42 PM

#5126176 Branching in switch statement

Posted by on 24 January 2014 - 02:06 PM


 I pretty soon discoverd that switch is an instruction that has nothing exclusive to the rest of instructions so I realized I will never need it.


Ehmmm.... actually... that is not quite right... switch does have something exclusive. A switch statement can - quite often - be realized through a jump table or something similar (performance!). I don't know of any compiler that can do that for a nested if statement (which is the only alternative to a switch). I have implemented quite a lot of programming languages myself (high level languages... Java, C#, Smalltalk, Javascript, some custom scripting languages) and I can assure you: If it's possible, use "switch" instead of nested IFs. It is very likely to be faster. I only talked about "interpreted" languages (the quotes are due to the fact that, of course, nowadays those are not really interpreted anymore, but just-in-time-compiled), but if I remember correctly from some previous posts from you, you are using C++... the thing about the jump table does also apply to C++ (which, in general, is not interpreted nor JIT'ed)

#5125751 Project Management Tools

Posted by on 22 January 2014 - 05:46 PM

My vote goes to the tools from atlassian: https://www.atlassian.com


First of all Jira is (IMHO) the best bug tracking system there is. Not exactly project management, I know, so...


They have a great product called "JIRA Agile" which is (again IMHO) great for managing software development (depending on your development process of course... if it's all waterfall for you, this will not help...)


The nicest thing are all the other (some 3rd party) great add-ons and plug-ins. You can have gantt charts, time management, integration of your git/svn/hg/cvs/mercurial/whatever repositories (FishEye), direct integration to your CRM systems...


And even if the marketplace does not offer the right thing, it is fairly easy to create your own plug-ins (I've written two so far - one for integrating our in-house time tracking system and one for integrating our in-house bug-tracker (no... we do not use Jira for that - unfortunately - we use it for project and development managment only)).


It is not free, but the "small" license (up to 10 users) is close to free ($10).


I guess, I better stop now, before this sounds like an atlassian marketing post (disclaimer: I am not in any way affiliated with atlassian, I just like their products).

#5114571 What reference book on C++ should a beginner buy?

Posted by on 05 December 2013 - 07:10 AM

Since you're asking for a reference book I would suggest this: http://www.amazon.com/The-Programming-Language-4th-Edition/dp/0321563840

#5063609 Pointer to an abstract class

Posted by on 21 May 2013 - 03:30 PM

You want to do that to make that class only accessible form that class usually, this is what a PIMPL implementation often uses, you should avoid pimpl it's a bad pattern. You shouldn't be hiding the data a class is operating on.

Not trying to derail the topic (sorry), but I'd like to hear more about your reasoning for this statement (the parts I've emphasized).

IMO there's nothing inherently wrong about the PIMPL pattern (except that it produces a lot of boiler plate code - but at the same time it enables nice things like implicit sharing and reducing compile times).
Besides, declaring the data class inside the actual class would not really be the PIMPL pattern, as the PIMPL would still be "public" (not in the language kind of way, but in the "I see what you did there" kind of way) in C++ as it could be seen in the header (you'd usually have a private header that's only included in the implementation not in the declaration; also, only when used like that, the PIMPL pattern can reduce compile time, which is one of its main merrits).
[EDIT - _very_ exaggerated, to be honest]: Actually, isn't PIMP the only true object orientated pattern? Afterall, one of the main points is encapsulation. What's more encapsulated than only showing the actual interface to the user? The user should not care "how" and "what data", but only "what can I do with it?".

Back to the topic: to me the question is lacking some information. What are you trying to accomplish? To me it seems like you are actually asking how to instanciate objects of the "Objects" and "Goods" classes (btw, get rid of the plural form)!? If that is the case, you will need actual implementation of the abstract classes. This is a long shot, though, since some information is missing here.

#5027366 [C#/C++]Multithreading

Posted by on 30 January 2013 - 05:02 PM

I don't know what kind of multithreading you did in C#, but from my experience it's not easier than in C++. So if you say, that multithreading in C# for all your needs is easy than either a) you're a freaking genius or b) your problems were perfectly fitted for multithreading.

Our brain is just designed in a way that it thinks sequential. Once multithreading comes into play, it's hard to even imagine what might happen and to think of all possible scenarios. Andrei Alexandrescu from the C++ consorptium pretty much naiiled it: "Multithreading is just one damn thing after, before, or simultaneous with another". And that's all we know.

When the code based is not designed for parallelism from the start it is a great step to adapt.

The funny thing is, that most of those people complaining about only one core being used would shut up, if you'd just create <number of cores>-1 threads in your program doing nothing but an infinite loop so they see 100% of CPU usage.

What I am trying to say is, that saying "...there's no simple way to make something multithreaded..." is very accurate. Usually, the first 2 or 3 attempts to parallelize a previously sequential algorithm/architecure will lead in full CPU usage but in slower execution.

#5024684 How to read file line

Posted by on 23 January 2013 - 06:19 AM

Judging by the question, you do not only want to read a line from a file, but also write it, right?

TextWriter writer = new StreamWriter("settings.dat");
TextReader reader = new StreamReader("settings.dat");
String colorId = reader.ReadLine();
String userName = reader.ReadLine();
Note that you also should do some error checking, right now bad things will happen if, for example the file cannot be opened or the file does not have two lines in it...

#5017399 Begining an editor

Posted by on 04 January 2013 - 02:52 AM

If you choose to compile Qt yourself there are two things that can greatly reduce the compile time:

1. Build Qt on all available cores: By default Qt will only be built on one core. If you have a multi-core CPU, that's annoying. In order to build it on all cores, open up the file <QTDIR>/mkspecs/win32-msvc2012/qmake.conf and find the line starting with QMAKE_CFLAGS. Add "/MP" (no quotes) to the end of the line and save the file (you should do this before running configure).

2. Don't build the examples and demos (you can always compile those that you need later): Open the file <QTDIR>/projects.pro and find the following text:

} else:isEqual(PROJECT, examples) {
     SUBDIRS += examples
} else:isEqual(PROJECT, demos) {
    SUBDIRS += demos

change them to

else:isEqual(PROJECT, examples) {
#       SUBDIRS += examples
    } else:isEqual(PROJECT, demos) {
#       SUBDIRS += demos

With those two changes it takes only about 20 minutes to compile Qt on my computer (including webkit). I do have a powerful computer, though (i7-2700K 4 cores/8 threads 3.5 GHz and 32 GB RAM).

#5017034 Begining an editor

Posted by on 03 January 2013 - 04:35 AM

Building Qt (4.8.4, didn't try 5 yet) 64Bit with VS2012 works without problems (if you disable webkit - if you need/want webkit, there's some work necessary). All you need to do is (inside a VS 64bit command prompt):

configure.exe -no-webkit <add more switches if you like, see configure.exe -? for all available options>

Works for me ™

#5011998 Open a file by tiping in its name in Visual studio 2010 c++

Posted by on 18 December 2012 - 05:44 AM

You can use the search box for this: just type in ">of myFile" (without quotes) and it opens the file.

As an alternative there are add-ons that do this. Visual Assist X, for example, has that feature.

#5009987 Can you create a Vector of structs in C++? I need help with a unknown error p...

Posted by on 12 December 2012 - 04:23 PM

There's absolutely no need to apologize.

Memory management in C++ is probably THE thing that a lot of people never get right and they just give up trying to learn C++ after a while. The basics are not THAT difficult, though:

The value of a variable has a "lifetime". This lifetime ends with the end of the current scope. I.e. it ends when the next "}" is encountered. So this:

if (true) {
  Rectanlge rect;
cout << rect.getX();

will lead to a compiler error since rect is not valid anymore at the point where rect.getX() is called. In the moment the closing "}" is encountered the Rectangle object called "rect" is destroyed. (Keep reading, I know, it's not a great example, since this is a compiler error, and the problem at hand is a runtime problem, just trying to get a feeling for scoping here...)

So for your case this means:
for(int j=0;j<8;j++){
   int ya=(j*50)-1;
   Rectanglee rect(Point(i,j),50,50);

every time the closing brace of the for-loop is hit, the object formerly know as "rect" is destroyed.

Now, your code saves the address of that object inside the vector. Too bad... the object is dead when the for-loop is left... So that address is nothing but garbage.So in your vector there's a whole bunch (well 8...) addresses that used to be Rectangle objects but are not anymore...

So now, let's look at the "new" keyword. The rectangless we've created so far were on the stack. Objects on the stack behave like I just said. They are deleted once the variable goes out of scope. The second kind of memory is the "Heap". When you use "new" this will create a new object on the heap. That object is valid and available until
a) the program is terminated
b) you use "delete" to ... well... delete it.
So this:
for(int j=0;j<8;j++){
   int ya=(j*50)-1;
   Rectanglee* rect = new Rectangle(Point(i,j),50,50);
(note: used a temporary variable to make it clearer) will create 8 new Rectangle object on the HEAP that will be valid even after exiting the for-loop. Now... This may be a problem. Who will ever invalidate (i.e. delete those Rectangles)? They will be on the heap occupying memory until the program is exited (thanks to modern operating systems) or until you explicitly remove them using "delete".

So, if you want to get rid of those rectangles (all of them) this would work:
for(int j=0;j<8;j++){
   delete rects[i];
This first deletes all the Rectangle objects that you've created on the heap and then clear the vector (because since we've just deleted all the rectangles, it contains nothing but a lot of addresses that formerly pointed to an object of type "Rectangle").

And this is exactly where smart pointers come in play... smart pointers help you to get rid of the burden to manually delete those objects that you've created on the heap, as they will automagically delete the object when there is no smart pointer left pointing at that object (it does not work all of the time [circular dependencies are a problem], but for a start it is pretty good)...

Hope this somewhat helps to get rid of the headache....

#5008070 Problem returning pointer from method

Posted by on 07 December 2012 - 03:40 AM

To be honest, I didn't dive too deep into the code, but the problem is that the connectionDestination of the Connection is never initialized (except for the NULL initialization in the Connection constructor). So at the end of the traverse method it will always return a NULL pointer, so currentRoom is NULL after calling traverse.

[EDIT] Damn... forgot to refresh. I opened the topic about two hours ago but then was away from the computer for a while...

#4991393 A "What's Next" Networking Question

Posted by on 18 October 2012 - 04:42 AM

There are services that provide dynamic dns lookup. This means that you install a little program that informs a server of your current ip address. It then routes the registered "domain" to that address. So basically, even though your actual IP changes there is a static hostname that will be updated whenever your IP changes.

There are several free providers for this kind of thing. One of the first ones (I think) was dyndns which I used for quite a while. There you registered a name (e.g. DontReferenceMyPointer.dyndns.com) and that one always pointed to your current IP address. However, looking at their website they don't offer a free service anymore. But I found a list of free provider: http://dnslookup.me/dynamic-dns/

#4985681 Visual Studio Express 2012 Yay

Posted by on 01 October 2012 - 02:32 AM

I really like VS2012 (using the professional edition) and I really like that the express edition can finally compile 64Bit applications out of the box (although it wasn't hard to set up in VS2010 either: install SDK -> chose it in the project's properties as the platform tools -> done).

What is really a problem is that (until now) applications compiled with VS2012 do not run on WinXP! Yes... WinXP is old and should not be supported anymore. I agree with that. BUT! As a developer of "professional" software (CAD/CFD software in my case) with many customers in Asia (China, Korea) I just have to live with the fact that a very big percentage of my customers use WinXP. So I have to wait for the promised upgrade: http://blogs.msdn.com/b/vcblog/archive/2012/06/15/10320645.aspx. I just hope it comes before our next release...

#4980455 License server and open ports

Posted by on 15 September 2012 - 12:58 PM

That would be an option. But, applications that go around scanning ports might trigger security mechanisms.

About the hassle that companys go through to use your software: It all depends on how unique (and good) your software is. If there is no alternative companys will do quite a lot of stuff to use it. But it would be very inconvenient if the customer has to manually type in the hardware information. Plus, instead of you obtaining the actual hardware information, I think it would need to be some kind of hashed value.
What I would do is to have the server generate a license request including the hashed hardware information at install time. Then send that to you. The license file is then generated at your site and sent back. Of course, this would be a lot nicer if you would actually have a server to contact instead of having to use emails for that. Depending on the expected number of sales processing those emails may get quite annoying on your side as well.
I would also not only use the MAC address(es) of the server as it is actually possible to change them.

Yes, creating your own license system is quite a hassle. So, again, looking into exiting ones might be worth it.

Overall, I agree with GWDev. Site licenses (for example key based, similar to windows licenses) are probably the easiest way to go.

#4980225 License server and open ports

Posted by on 14 September 2012 - 05:46 PM

I don't understand your use case, why does the client have access to the license server? Doesn't that defeat the point?

Actually, not at all. As already mentioned, especially in the CAD/CAE/CFD field many license models work like that (e.g. StarCCM+, Flowtech Shipflow, NUMECA tools). You get a license issued to a server and several clients can connect to it. FlexLM is a great (and most commonly) used program to achieve that.

Back to the OP...
I assume FlexLM is no option for you. If we are talking about a software where each license is worth a couple of thousands dollars (or euros or the equivalent value in any other currency), then I'd say looking into professional solutions for this problem is definitely worth it. Again (as I am working in the CAD/CFD field and have good experience with it) FlexLM would be a very good option in that case.

Now, if you really want/need to roll your own:
Having a server application with non-configurable ports is a no-go imho.

First of all, (of course) the floating license needs to be node locked to the server it runs on. I assume that's a given, but I'd still like to stress it. HDD-serials and MAC-addresses are good candidates for that. They are easy to get from the OS and rarely change. Limiting the license to the OS is also a good way to go, to avoid "cracking" your license using parallels, for example.

To circumvent the problem of having multiple servers on the same machine I would take a shared memory approach. I don't know what language your server is in, but for C++ the boost interprocess library offers a ncie API.
I'd generate a signature based on the hardware infos stored in the license (which are neccessary and would prevent the license from working on that particular machine if they were changed) and put that into the shared memory. Then have every instance of the server access that shared memory and look for that signature. If it's there, the license is in use and cannot be used again. If it isn't, store the signature in the shared memory which locks it for other instances of the server.

About the VM thing... Sure if the original license was issued for a VM, it is possible to clone it which would cause the same hardware IDs to be generated and then multiple VMs could run on the same license.
However, for most VMs (VMWare, Virtual Box, for example) there are pretty good methods to detect them. It usually involves using some inline assembler, but google it, and then it's only copy paste ;)
So I would actually put a check in the server (which we do for our software, btw.) to prevent it from running on a VM. You might even put a switch in your license to allow customers that can explain why they want to run the server in a VM to do so (which we do).