|
No, exact size doesn't matter. Just more than approximately 400.000 numbers.
|
|
|
|
|
You missed my subtlty. If you have 160,000 numbers and each is 4 bytes in size, that would require 1.28MB of stack space, obviously more than the default size of 1MB. Using the stack, I'd be surprised if you could get any more than 130,000 numbers.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
So, you are saying that default and maximum size of stack size is 1 MB?
I solved this problem with using vector, but still I want to know a C++ mechanisms
|
|
|
|
|
vonpik wrote: So, you are saying that default...size of stack size is 1 MB?
Yes.
vonpik wrote: I solved this problem with using vector,
Which gets its memory from the heap, not the stack.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I've been trying to use the Boost serialization library to make some data persistent. Nothing particularly fancy but I have some objects from the wxWidgets library included. What a PITA!
Ok, I admit I may be a bit late to the party. I've dabbled a little with my own template classes over the years but nothing extensive as I've just not had the need. So I'm not nearly as facile with them as I am with the rest of the language.
But when the compiler generates an error on a template, it would be nice if it gave you a half way decipherable description of the real problem. It also appears that the compiler doesn't even parse some of the stuff in the template declarations until it actually decides to instantiate it. You're down to one error in the compile and think you've got it knocked and her comes another cascade of a page of errors. Or actually one more error with a page of crap not telling you what's wrong.
The Boost serialization library, IMNSHO, needs considerably more documentation and more extensive examples.
Thanks, I needed that.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
...to the jungle.
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]
|
|
|
|
|
Finally! Guess I missed a const declaration on one of the templated member functions. Maybe if it had told me it had problems converting beteen const T& and T& rather than const T and T& or something like that, I might have tumbled to it. And left out some of the other garbage along the way. I guess the moral of the story is to unit test templated classes or classes with templated functions incrementally as you go and make sure they each work before you barge ahead because the compiler said everything is ok. Guess when I noticed that it wasn't warning me about an unused parameter, I should have been suspicious that it didn't really care.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
You're seeing one of the fundamental defects in programming with templates. Implementing them to the standard is just so freaking complicated that compiler designers don't seem to be able to issue decent diagnostics for them. The point at which they detect problems is so far removed from the original source that they can't associate the two. VC6 was notoriously bad about it (its template support was incomplete), and VS2003 wasn't a whole lot better.
My main source of never-ending grief is ">>" versus ">{space}>". In some cases, the compiler will handle the first token as a shift operator, in others it's the tail end of a templated argument to a template.
One issue with Boost is that it's pretty much all-or-nothing. Most of the Boost libraries do not like to be mixed with other libraries such as MFC or ATL. I've successfully used Boost.RegEx in an MFC app, but that's it. I would imagine Boost requires that your wxWidget objects have certain Boost-specified characteristics, and they don't. You might need to encapsulate them in your own objects for serialization purposes.
|
|
|
|
|
Gary R. Wheeler wrote: Implementing them to the standard is just so freaking complicated that compiler designers don't seem to be able to issue decent diagnostics for them. The point at which they detect problems is so far removed from the original source that they can't associate the two.
I think that's a big reason I sat on the bench about them for so long. When I played with them in the past, I didn't really need them so it was more of an academic exercise. Then I just got frustrated with them and bagged it. I'm using VC++ 20008 now and it doesn't choke as much but diagnostics aren't much better.
Gary R. Wheeler wrote: My main source of never-ending grief is ">>" versus ">{space}>".
I got bit on that one early and now, if I'm on my game, remember to look for it. Part of the whole finicky somewhat arcane notation which has to be just so or you're scratching your head again about compiler errors.
Gary R. Wheeler wrote: Most of the Boost libraries do not like to be mixed with other libraries such as MFC or ATL.
Gary R. Wheeler wrote: I would imagine Boost requires that your wxWidget objects have certain Boost-specified characteristics, and they don't. You might need to encapsulate them in your own objects for serialization purposes.
Yes, ran into that one but fortunately so far I'm only serializing two, wxColor and wxString. I first tried deriving serializable classes from them but ran into problems. Now I just have a data container to shadow wxColor and create an instance to do the serialization at the point it's needed. For wxString, I convert it to an std::string and go from there. I'm sure as time goes on, I'll be building up the repetoire but that's a bridge that can be double crossed later. On top of that, I'm using OpenCV, too, with its own set of simple primitives but since it's a C API, it will be a bit easier as the data is public for most of it.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Hi all,
i want to set service center number so i m using AT+CSCA command.
AT+CSCA="Service center no",145
but its not set succssfully,return a string with addition of ERROR.
but in some mobiles its working fine.
please help me for this.
|
|
|
|
|
I am using c++. In one method (subroutine) I need to implement three independent random number generators. I do not know how to isolate them from each other. I am using a subroutine ran1(ikum) from Numerical Recipes. I other words, the seed of the random generator must be independent.
Thanks
|
|
|
|
|
Here it is
int rand1()
{
srand(time(NULL));
return rand() % 100 + 11;
}
Now similarly u can create a few other one srand(time(NULL)) will generate different sequence on startup.
Just refer
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks a lot.
In fact, I have to generate three indenpendent random numbers with the same for loop.
For (int i=0;i
|
|
|
|
|
Just check this.
int rand1( int nData)
{
return rand() % 100 + nData;
}
int main(int argc, char *argv[])
{
int Temp;
srand(time(NULL));
for( int i = 0; i< 11; i++)
{
Temp = rand1(1) ;
cout<<"Num1=="<<temp<<endl;
temp="rand1(2);
" cout<<"num2="="<<Temp<<endl;
" cout<<"num3="="<<Temp<<endl;
" }
="" return="" 0;
}
<div="" class="signature">Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks.
I am using a different random number generator which generates a normal distribution of a random number generator - N(0,1). This function is from a book called: Numerical Recipes.
When I call it, I call gasdev(int &idum); For example: t=time[i]+sd_error*gasdev(int &idum);
In one subroutine, I need to call gasdev(int &idum) three times, but I want each time it is independent.
int idum1=-1;
int idum2=-1;
int idum3=-1;
//
date=time[i]+t_sd_error*gasdev(idum1);
money=t_sd_error*gasdev(idum2);
force=force_sd_error*gasdev(idum3);
date, money, and force are totally independent variables. Do you think I am OK to make the three calls independent with above idum1, idum2, and idum3 ?
Here is it:
//
double C_procDlg::ran1(int &idum)
{
const int IA=16807,IM=2147483647,IQ=127773,IR=2836,NTAB=32;
const int NDIV=(1+(IM-1)/NTAB);
const double EPS=3.0e-16,AM=1.0/IM,RNMX=(1.0-EPS);
static int iy=0;
static int iv[100];
int j,k;
double temp;
if (idum<=0||!iy) { //initialize
if(-idum<1) idum=1;
else idum=-idum;
for(j=NTAB+7;j>=0;j--){
k=idum/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if(idum<0) idum+=IM;
if(j<NTAB) iv[j]=idum;
//
}
iy=iv[0];
}
k=idum/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if (idum<0) idum+=IM;
j=iy/NDIV;
iy=iv[j];
iv[j]=idum;
if((temp=AM*iy)>RNMX) return RNMX;
else return temp;
}
//
double CBlast_vib_procDlg::gasdev(int &idum)
{
static int iset=0;
static double gset;
double fac,rsq,v1,v2;
//
if(idum<0) iset=0;
if (iset==0){
do{
v1=2.0*ran1(idum)-1.0;
v2=2.0*ran1(idum)-1.0;
//
rsq=v1*v1+v2*v2;
}
while(rsq>=1.0||rsq==0.0);
fac=sqrt(-2.0*log(rsq)/rsq);
gset=v1*fac;
iset=1;
return v2*fac;
}
else{iset=0;
return gset;
}}
modified on Saturday, April 10, 2010 1:58 AM
|
|
|
|
|
What do you think if I use your above code to generate three seeds for my three random number generators?
My aim is to generate three random number sequence which are totally un-correlated each time to run the program?
Thanks
|
|
|
|
|
I believe this logic surely generate new sequences, but remember that
rand() % X + nData;
If the value si X is bigger then there is less chances that the same number is repeated.
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks. I like you to do more comments. What you suggest ?
|
|
|
|
|
Thanks. Your above code works. I will use it to generate seeds for a generator of a normal distribution diviates
|
|
|
|
|
Hi, I created a thread in CView::OnInitialUpdate method of my CView class now I want to know how could I post my mouse move, wheel, RClick messages, (captured by CView) to the started thread, I have saved my thread pointer in m_pThread datamember.
a simple code would make the case more clear to me,
Regards
|
|
|
|
|
|
Thank you,
But what do I put to the the third and 4th arguments?
BOOL CMyView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
::PostThreadMessage(m_pThread->m_nThreadID, WM_MOUSEWHEEL, ???, ???);
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
|
|
|
|
|
Use MAKELPARAM and MAKEWPARAM to set the delta and point. as the next parameters.
Величие не Бога может быть недооценена.
|
|
|
|
|
Fellow coders,
RE: a C++ design problem.
I am attempting to construct a C++ class hierarchy on top of a C legacy system. The result
will be then placed into an embedded controller. The controller communicates with a Windows
program via a series of 'software pipes' to a supplied DLL and then calls in the Windows
program to fetch information from the DLL. The data in a given pipe will be of a specific type.
In order to generalize this process the third party library uses the following header:
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef union gen_scalar {
double _double;
__int64 _i64;
float _float;
long _i32;
short _i16;
DWORD _long;
WORD _word;
BYTE _byte;
} GENERIC_SCALAR;
And then, for example, reading a long from a pipe would be:
long Get(PIPE* pipe)
{
GENERIC_SCALAR v;
pipe_value_get(pipe, &v);
Return v._i32;
};
So, the hierarchy starts with a base class:
class Pipe
{
public:
Pipe(PIPE* pipe)
: pipe_(pipe)
{};
virtual ~Pipe()
{};
protected:
PIPE* pipe_;
};
where a PIPE* is just a handle to the communication pipe.
Then an input class is needed:
class IPipe : public Pipe
{
public:
IPipe(PIPE* pipe)
: Pipe(pipe)
{
pipe_open(pipe_, P_READ);
};
};
There would also be a corresponding output class OPipe.
And now the part I need help with!
Suppose I know a pipe will contain a series of 'shorts'. Then I could create:
class ShortIPipe : public IPipe
{
public:
ShortIPipe(IPIPE* pipe)
: IPipe(pipe)
{};
short Get() const
{
GENERIC_SCALAR v;
pipe_value_get(pipe_, &v);
return v._i16;
};
};
And so on for a long, double, float, etc, pipe(s).
However, the only difference between all these classes is the return value, that is,
v._i16 or v._i32, etc.
I'd prefer to create a single class which can handle them all. Maybe a template class?
For example:
template <typename T>
class IPipe : public Pipe
{
public:
IPipe(PIPE* pipe)
: Pipe(pipe)
{
pipe_open(pipe_, P_READ);
};
T Get() const
{
GENERIC_SCALAR v;
pipe_value_get(pipe_, &v);
return v._???;
};
};
Used like:
IPipe<short> spipe(...);
short s = spipe.Get();
And so, (finally) the question is how, within the Get() member, do I define the return value?
Note: the embedded controller cannot support RTTI. And I'd prefer not to have a big switch.
Any help would be much appreciated!
Kylur.
|
|
|
|
|
How about Template specialization?
template<> class IPipe<short>
{
...
return v._i16;
...
}
template class IPipe<long>
{
...
return v._i32;
....
}
|
|
|
|
|