• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Visual Studio C++

coder_t2

[H]ard|Gawd
Joined
Dec 31, 2005
Messages
1,166
Hey guys, I am trying to familiarize myself with multi-processor coding. So I created a C++ project in Visual Studio to get on my way with it. However, for textboxes it uses this weird String ^ object type. Been trying to figure out how to convert it into a int, or char* or something else, but nothing works. Does anyone know anything about this. Google wasn't very helpful.
 
You're probably creating a .NET Managed C++ project where C strings aren't really allowed as they aren't managed. Programming in .NET is very different from standard C++ and you need to use the .NET class library and types instead of the standard C++ libraries.
 
Hey guys, I am trying to familiarize myself with multi-processor coding. So I created a C++ project in Visual Studio to get on my way with it. However, for textboxes it uses this weird String ^ object type. Been trying to figure out how to convert it into a int, or char* or something else, but nothing works. Does anyone know anything about this. Google wasn't very helpful.
Handle (^)
http://msdn.microsoft.com/en-us/library/yk97tc08(VS.80).aspx
gcnew (garbage collected new)
http://msdn.microsoft.com/en-us/library/te3ecsc8(VS.80).aspx
Interior pointer (aka handle/hat)
http://www.codeproject.com/KB/mcpp/interiorpointers.aspx
 
You're probably creating a .NET Managed C++ project where C strings aren't really allowed as they aren't managed. Programming in .NET is very different from standard C++ and you need to use the .NET class library and types instead of the standard C++ libraries.

That's really lame. I am trying learn some new skills for future jobs. I doubt C++ .NET is used much by companies. Usually C# if using .NET. Think it is worthwhile to learn how to do multi-threaded apps in C#?
 
That's really lame. I am trying learn some new skills for future jobs. I doubt C++ .NET is used much by companies. Usually C# if using .NET. Think it is worthwhile to learn how to do multi-threaded apps in C#?

Why do you doubt that? It gives you many to all of the benefits of .NET with the native ability to use existing c++ libraries and system calls...
 
I guess because it using these weird self contained pointers for String, which is what is returned by the Text property of many .NET visual objects. But since .NET isn't all Windows Form stuff, I retract my original statement about companies not using .NET C++. I was just getting frustrated with it. I am just using C# atm to learn multi-threading. At least I'll understand concepts, and the syntax won't be that different for C++.
 
You don't *have* to use managed C++ if you don't want to, you can certainly set your project up as a plain old unmanaged C++ project and use the STL or cstrings if you want. Or even *shudder* Win32.
 
Why not use native C++ with threading from Win32 API?

_beginthreadex / CreateThread

Managed C++ just adds extra complications, and I don't see much future in it, as a technology. That's just my opinion though.
 
Ok. So I have been playing threading in C# and I got it to work nicely enough. Just been doing some basic stuff to understand it. But I want to be able to utilize multiple cores on a computer. What keywords should I use to find a tutorial on google for this. At first I thought multi-threading was it, but apparently not.
 
Ok. So I have been playing threading in C# and I got it to work nicely enough. Just been doing some basic stuff to understand it. But I want to be able to utilize multiple cores on a computer. What keywords should I use to find a tutorial on google for this. At first I thought multi-threading was it, but apparently not.

What's the problem? Are you trying to say that your threads are not using multiple cores? They should be.
 
They aren't, at least it appears that way. The multi-threading does make things smoother. Like no lockups and such, but it isn't using 100% CPU, only 50%. Just as it was before I added threading. I am just doing a simple of having a for loop go through a count, and a label to output each number. There are 3 labels and each has a loop that runs simultaneously.
 
Nevermind. Apparently it wasn't pushing the CPU hard enough. I created a Mersenne Prime calculator and that pushes it to a 100%.
 
ok new question. Anyone know how to calculate numbers larger than 64 bits? Been using Int64, but I want to calculate numbers larger than that. Trying to do it via a string, but it is proving to be a lot of work since I have to custom create every math function.
 
There's nothing included in the standard libraries to help with this, and obviously no primitive types. Either build a large integer class (there are a bunch of ways to implement it...), or use one of the libraries available to you. In .NET you'd use BigInteger, though most other libraries will have similar classes available. Or if you want to stick to standards compliant C/C++ and don't want to implement it yourself you could use GMP.
 
ok new question. Anyone know how to calculate numbers larger than 64 bits? Been using Int64, but I want to calculate numbers larger than that. Trying to do it via a string, but it is proving to be a lot of work since I have to custom create every math function.

It's a good exercise to figure out how to do large math. Even simple things such as addition and subtraction. Try creating your own math library and overload the functions, starting with + and - then moving on. You might find it very rewarding.

Alternatively, grab a pre-rolled library (such as those keenan recommended) and go for it.
 
It's a good exercise to figure out how to do large math. Even simple things such as addition and subtraction. Try creating your own math library and overload the functions, starting with + and - then moving on. You might find it very rewarding.

Alternatively, grab a pre-rolled library (such as those keenan recommended) and go for it.

I agree. I wouldn't mind seeing some example code. Or even a general concept. Currently I am just trying to do it with strings. Not really doing it as good as I would like. But just trying to get the Mersenne Prime algorithm rocking. And the only point of that was to test multi-threading. Lol. Funny how this project keeps evolving and I need to keep creating new things.
 
For a simple implementation, think back to how you learned to do arithmetic in grade school. The algorithms you will need to implement are similar; you will need to handle carrys and so on in the same fashion while looping over the digits. There are much more efficient approaches that can leverage the built-in 32 and 64-bit arithmetic operations and do some further tricks, but the naive approach is fine and a good learning experience, it's a pretty standard assignment in early comp sci courses.

Strings are not a bad representation for the naive approach, though it might make life a little easier to think of the string as an array if int8's instead, that way you're not translating between ASCII and binary all the time, just storing a single 0-9 digit as an 8-bit integer. If you want to get clever, you can pack two digits into a single byte. Even using ASCII strings though you're heading down the right path (at least for the sensible, but inefficient approach) of treating a large integer as an array of digits, now all you need to do is translate your basic artihmetic skills to C methods ;).
 
I agree. I wouldn't mind seeing some example code. Or even a general concept. Currently I am just trying to do it with strings. Not really doing it as good as I would like. But just trying to get the Mersenne Prime algorithm rocking. And the only point of that was to test multi-threading. Lol. Funny how this project keeps evolving and I need to keep creating new things.

e.g. To add 2 8 bit (1 byte, aka "char" in c/c++) numbers with overflow:

Code:
 10000000
 10000000
 --------
100000000

Which could be represented by an array containing:
[0] 00000000
[1] 00000001

To do the math, then, you need something bigger than your number... the easiest is to go twice as big, so use a short to store the result of two bytes. You can then store the lower and upper parts using masking and shifting.

e.g.
short added = byte1 + byte2;
array[0] = (char)(added & 0xff)
array[1] = (char)( (added >> 8) & 0xff)

Make sense?
 
So I created a unlimited sized integer class using strings. It works, albeit very inefficiently. So I am working on creating a more efficient class. I like the idea of doing bit shifting. But how do you represent a number back to decimal, if you were using an array for bits?
 
Back
Top