I am writing a code in c++ unix environment using gmp for impelementing quadratic sieve
I have many global variables i.e the number to be factorised and some arrays, sievelength,factorbase siz etc. During the first part of the program, the program simply calculates the factor base implemented through a fucntion compute factor base(), which currently is in my main() program. I want to move the function definition to another file and only call the function in main() , is there any way other than explicitly passing all the variables to the function???

Recommended Answers

All 2 Replies

Sounds like you should create a struct to contain all the globals and simply pass the address of the struct variable. If the struct definition is in a header file included where need be you would be able to use it that way. Globals can always be eliminated. Something to keep in mind.

thx Frederick even I thought of the same.. just wanted to make sure this is standard practice...actually I had other queries too, but not sure whether posting in this thread is appropriate, if need be I will created a new thread
My program would eventually eat a lot of memory 100's of MBs in this light... I thought that some data should be created as arrays (upper limit 200kb) ... for example the factor base may contain upto 10000 entries for 80 digit numbers(though for small numbers it would be much lesser), instead of using dynamic structures like vectors etc...just wanted to know is this good programming practice or I should use dynamic structures ?...also if someone has experience in using gmp in c++ for similar applications kindly inform on the thread so that I would pose those queries in a new thread.. the internet does not have enough information on this and it might e useful for many others..thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.