|
Yes, that's why I said it could be his *best bet*.
[Military tone] Sir, we need to keep a safe distance from him. [/Military tone]
It is a crappy thing, but it's life -^ Carlo Pallini
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Rajesh R Subramanian wrote: The Output: A very laaarge number[^]
order 6 of magnitude apart
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Rajesh R Subramanian wrote: GMP BigNum library[^] is your best bet perhaps.
Rajesh, do you know of any good implementations of BigNum that are not Gnu based, i.e. use MS tools like MASM? I have Googled "multi precision math" and went through all of the hits, and the results (there were 97) were all about BigNum, or proprietary for sale products, or for Java, or were white papers. Nothing there about a PC based MS implementation. I even searched the CP articles and found no hits.
I downloaded the GMP version and started looking at the ASM source, but without the GCC compiler and its tools, the code is not complete. It needs to be expanded by the Gnu M4 macros and assembled by GAS (Gnu Assembler?), and even then I don't know whether or not it produces anything like a .LST file that would actually indicate exactly what instructions are executing at which locations to gain their reported speed by taking advantage of cashing, etc. I really don't want to go this route, I want to stick with MS tools and don't even want the C++ front end, strictly MASM.
I do have an integer implementation of a multi precision math library and was thinking of expanding it to a floating point version and was looking to see how it stacked up with "the best". As far as I could easily determine, the BigNum algorithms matched mine. Mine were home brew - what worked fastest, theirs were based on the experts like Knuth. I went to my library and cracked open Knuth, Vol 2, for the first time to see what the expert had to say. Enlightening. I have also done a thorough read of the AMD specs on my Athlon and have used many of their suggestions.
Dave Augustine.
|
|
|
|
|
Dave,
I am not able to suggest something readily that might suit you. Further to that, I have not worked too much on this front. I have forwarded this query to a few people that might possibly give a fruitful reply.
I'll write to you if I hear something from them.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh,
Thank you for your help. I'll be waiting to hear if any of your contacts has anything.
What really supprised me was that the Code Project didn't have anything at all about this.
Dave.
|
|
|
|
|
Yes: 1GB file.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ROTFL.
It is a crappy thing, but it's life -^ Carlo Pallini
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
trioum wrote: storing the largest number
A number with 1000000000 digits is the largest number? Cool,
that simplifies my life considerably!
trioum wrote: is there any data type is which I can store the 1 billion digit numbe
You can easily make your own type.
Assuming you only need to work with digits 0-9, you only need
four bits per digit. That means two digits will fit in a byte.
Write a class to wrap a 500000000 byte array and cross your fingers
that you are actually able to allocate that much in one chunk.
A backing store on the harddrive may help here - perhaps a memory
mapped file. In the class, provide whatever methods you need to access
the digits.
Easy.
Good luck,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Assuming you only need to work with digits 0-9, you only need
four bits per digit. That means two digits will fit in a byte.
Write a class to wrap a 500000000 byte array and cross your fingers
that you are actually able to allocate that much in one chunk.
Thank you sir. Now I need an array of the above class instances. The array should have 1 billion elements...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Now I need an array of the above class instances. The array should have 1 billion elements...
Vaya con Dios my friend.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Store? Even if each digit were 1 byte, that'd require 1GB of memory. Perhaps you could explain your requirements a bit so we could possibly offer an alternative solution.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hello together,
I've tried to return a string back from a C++ dll function within VB and it is working fine, but if I try to use the same function in a C++ project it returns garbage !
does anyone know what I have to do different ? as I want to use the function in C++ as well as in VB is there a way to implement the function to fit for both languages ?
my C++ dll function:
BSTR __stdcall ReturnString2Vb(void)
{
char* str = "This is a test string...";
return SysAllocStringByteLen(str, strlen(str));
}
thanks a lot in advance for any help !
ganralf
|
|
|
|
|
Possibly it doesn't return garbage, it returns a BSTR . You may, for instance, use _bstr_t wrapper class to handle it in your C++ application.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi Pallini,
thanks for your quick answer !!!
do you mean I have to replace BSTR by _bstr_t ? I tried it in the following way but now I get a compile error that tells me that the _bstr_t data type is not defined. Which header do I have to include in my C++ project ?
_bstr_t ReturnString2Vb(void)
{
char* str = "This is a test string...";
return SysAllocStringByteLen(str, strlen(str));
}
would be great if you could report me an example
maybe important: the dll I created is a win32 dll not a MFC or similar
thanks in advance for your help !
ganralf
|
|
|
|
|
ganralf wrote: do you mean I have to replace BSTR by _bstr_t ?
Nope.
In you client C++ application you may use _bstr_t as wrapper for the BSTR return value. You know, BSTR stands for OLECHAR * , i.e. like a wide char string, you may also handle directly it in you client app.
With VS6 compiler you need to include comdef.h to use _bstr_t class.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ok, thanks Pallini ! it now seems to compile and link but the result is the same
dll function
BSTR ReturnString2Vb(void)
{
char* str = "This is a test string...";
return SysAllocStringByteLen(str, strlen(str));
}
C++ application code
int _tmain(int argc, _TCHAR* argv[])
{
_bstr_t returned_string;
returned_string = ReturnString2Vb();
return 0;
}
as I am new to C++ and if it would be no great effort for you I think it would be helpfull if you could change the above mentioned code so that it will work.
thanks in advance !
ganralf
|
|
|
|
|
What does the following C++ application ouputs
int _tmain(int argc, _TCHAR* argv[])
{
BSTR returned_string;
returned_string = ReturnString2Vb();
wprintf( L"%s\n", returned_string);
printf("%s\n", (const char *) returned_string);
return 0;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Saturday, October 18, 2008 9:22 AM
|
|
|
|
|
well it outputs "????????????" in the console window but not the string !
thanks !
ganralf
|
|
|
|
|
Well, I'm very sorry I misread your SysAllocStringByteLen call (as SysAllocString ) . I've fixed my previous reply, please have a look at.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanks Pallini,
that's it now it works ! I have changed the application code as follows:
BSTR ReturnString2Vb(void)
{
char* str = "This is a test string...";
return SysAllocStringByteLen(str, strlen(str));
}
int _tmain(int argc, _TCHAR* argv[])
{
char* returned_string;
returned_string = (char *)ReturnString2Vb();
return 0;
}
again thanks for your help !
ganralf
|
|
|
|
|
You're welcome.
BTW don't forget to call
SysFreeString(returned_string);
when you no loger need it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ganralf wrote: f I try to use the same function in a C++ project it returns garbage !
How are you determining that it returns garbage?
From the SysAllocStringByteLen() docs:Takes an ANSI string as input, and returns a BSTR that contains an ANSI string. Does not perform any ANSI-to-Unicode translation. It's a safe guess that code that takes a BSTR expects the string to be in UTF-16. Use SysAllocString() instead.
|
|
|
|
|
Hi Michael,
thanks for your reply !
I tried SysAllocString and it works fine within a C++ project but if I try to return the string in Excel VBA it returns "T h i s i s a t e s t s t r i n g . " (every sign in the string is separated by a sign that cannot be displayed) and in VB it returns "T"
C++ dll function code
BSTR __stdcall ReturnString2Vb(void)
{
return SysAllocString(L"This is a test string.");
}
VB code
Private Declare Function ReturnString2Vb Lib "C:\testdll.dll" () As String
Function ReturnString() as string
Dim returned_string As String
returned_string = ReturnString2Vb()
end function
what am I doing wrong ? when I am using SysAllocStringByteLen all is working fine !
thanks for your help !
ganralf
modified on Sunday, October 19, 2008 7:58 AM
|
|
|
|
|
I have a section of shared memory divided into 4 areas, but I would like to use memcpy() to update each section without affecting the other section.
I have a pointer memPtr;
int *memPtr;
Can I just use:-
memscpy(memPtr, sizeof(section[0]), section[0]);
and then
memcpy(memPtr + sizeof(section[0]), section[1]);
i.e. the total ares is
MyStruct section[4]; and would like to update section[0] and section [1] as required
Thanks,
Andy.
|
|
|
|