473,388 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Require help/suggestion

Hey guys, I am new to this group.. i never know wot s going on in this
group.. but wot made be brought here is cpp.. guys am currently a
part of onw reaserch ... am new to everything.. i can prog in c and
a bit in cpp.. to say ..am a fair programmer... there is a new
problem in my research work.. which if solved , gives me a gud tool
to develop my prog in a much better way.. lemme describe my prob...

i have a routine in my prog which is currently calculating some (N-L *
L )matrixes... where both N and L vary.... so i have got a set of
matrixes which are varying in dimensions. n guys , wots the wrost part
is ... i am calculating these same matrixes again n again... waste of
time and memory... forget abt storing in memory, forget abt
recalculating them... i need to write these dimensionally varying
matrixes on to a file.. and read bak my one particular matrix bak again
when ever i need it. u can imagine ..N and L are in hundreds.. and i
need to get bak my required matrix from the pool of matrixes in a
file.. and one more thing... i cant use different files for different
matrixes.. alll of them must be contained in one single file.. and each
matrixes boundries must be well defined.. help me out buddiess....
how can solve this problem.. i will be thankful if u guys can give
me a solution to this problem...and i dont have much time also, so
please make it quick. Thank you buddy,

Sandeep Chandra

Nov 22 '05 #1
13 1599
sandeep chandra wrote:
Hey guys, I am new to this group.. i never know wot s going on in this
group.. but wot made be brought here is cpp.. guys am currently a
part of onw reaserch ... am new to everything.. i can prog in c and
a bit in cpp.. to say ..am a fair programmer... there is a new
problem in my research work.. which if solved , gives me a gud tool
to develop my prog in a much better way.. lemme describe my prob...
Especially for non-native speakers of English, it really would help if your
spellings looked familiar: the sound-letter correspondence in English is
far from a bijection, which makes it sometimes hard to guess which word you
abbreviate.

i have a routine in my prog which is currently calculating some (N-L *
L )matrixes... where both N and L vary.... so i have got a set of
matrixes which are varying in dimensions. n guys , wots the wrost part
is ... i am calculating these same matrixes again n again... waste of
time and memory... forget abt storing in memory, forget abt
recalculating them... i need to write these dimensionally varying
matrixes on to a file.. and read bak my one particular matrix bak again
when ever i need it. u can imagine ..N and L are in hundreds.. and i
need to get bak my required matrix from the pool of matrixes in a
file.. and one more thing... i cant use different files for different
matrixes.. alll of them must be contained in one single file.. and each
matrixes boundries must be well defined.. help me out buddiess....
how can solve this problem.. i will be thankful if u guys can give
me a solution to this problem...and i dont have much time also, so
please make it quick. Thank you buddy,


Just a request for clarifications:

a) Is this a "compute and write once -- read often" type of thing, or will
you need to write back changes to the matrices stored in the file?

b) If you need to update matrices in the file, will the size of the matrix
still be the same or might it change, too? (This would rule out some simple
minded ideas.)

c) Why is it that you cannot use different files for different dimensions of
the matrix? Do you just have a maximum number of files due to OS
constraints or is there is an unmentioned design constraint that says you
may use only one file? If so, why.

d) Do you need the data in the file to be persistent, i.e., remain existent
and meaningful after the program finished?
Best

Kai-Uwe Bux

Nov 22 '05 #2
sandeep chandra wrote:
Hey guys, I am new to this group.. i never know wot s going on in this
group.. but wot made be brought here is cpp.. guys am currently a
part of onw reaserch ... am new to everything.. i can prog in c and
a bit in cpp.. to say ..am a fair programmer... there is a new
problem in my research work.. which if solved , gives me a gud tool
to develop my prog in a much better way.. lemme describe my prob...

i have a routine in my prog which is currently calculating some (N-L *
L )matrixes... where both N and L vary.... so i have got a set of
matrixes which are varying in dimensions. n guys , wots the wrost part
is ... i am calculating these same matrixes again n again... waste of
time and memory... forget abt storing in memory, forget abt
recalculating them... i need to write these dimensionally varying
matrixes on to a file.. and read bak my one particular matrix bak again
when ever i need it. u can imagine ..N and L are in hundreds.. and i
need to get bak my required matrix from the pool of matrixes in a
file.. and one more thing... i cant use different files for different
matrixes.. alll of them must be contained in one single file.. and each
matrixes boundries must be well defined.. help me out buddiess....
how can solve this problem.. i will be thankful if u guys can give
me a solution to this problem...and i dont have much time also, so
please make it quick. Thank you buddy,

Sandeep Chandra


The problem doesn't seem very difficult for a 'fair programmer', what
part are you struggling with?

To solve it however more information is needed, for instance are there
any limits on the number of matrices that you will store in this file?
You say you need only one file, would it be reasonable to use two files?
One file would act as an index into the other file.

john
Nov 22 '05 #3

"sandeep chandra" <sa***************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hey guys, I am new to this group.. i never know wot s going on in this
group.. but wot made be brought here is cpp.. guys am currently a
part of onw reaserch ... am new to everything.. i can prog in c and
a bit in cpp.. to say ..am a fair programmer... there is a new
problem in my research work.. which if solved , gives me a gud tool
to develop my prog in a much better way.. lemme describe my prob...


Since you're new to the group, let me make a suggestion regarding posts you
make here:

Please use complete sentences. And complete words, for that matter. This
is not Instant Messenger, or a cell phone. Reading the above paragraph is
like reading old telegrams from the World War 2 era. If you want help, take
the time to write legibly, and we're more likely to take the time to read
and respond, ok?

-Howard
Nov 22 '05 #4
Hi Kai,

Sorry for replying late and sorry for my abbrivation with english. ok
let me come to the point.

a) yes, it is compute once and read often type...but there might be
some cases where i need to append the file with more matrixes

b)The size of the previously calculated matrix does not change, only
the new ones get appended.

c)I just dint want to create a mess of files on the output folder as i
already have a lot of them. Moreover there will be hundreds or
thousands of matrixes, so it will be messy to create so many files.
There is no such rule, if we can avoid that mess.

d) the data need not to be persistent. program needs it, it need not
mean anything to user.

I admit that am not a good programmer, please see it from my
prospective. Thank you and sorry again for my bad english. Thank you.

Sandeep

Nov 22 '05 #5
Hey john,

I admit that i am not a good programmer, am still in the early stages
of programming.. Why would an Electrical engineer needs to be a c++
guru??.. any ways i need to do this work, so i have to do the
programming whether i know it or not. So plese try to understand my
problems with cpp. Let me come to your question.

Yes it is very good idea to use one file as an index to another. I have
no restriction to use only one file , but i need to keep them from
creating a mess. It would be really helpful for me if u can provide me
with the details of the coding part. I apologise for my late reply .
Thank you,

Sandeep

Nov 22 '05 #6
Hey Howard,

I am very sorry for my english. I was a bit casual with my language.
Now i can understand the problems with such type of english, especially
to non-english speakers. Thank you for your notice and sorry once
again. Thank you.

Sandeep

Nov 22 '05 #7
sandeep chandra wrote:
Hi Kai,

Sorry for replying late and sorry for my abbrivation with english. ok
let me come to the point.

a) yes, it is compute once and read often type...but there might be
some cases where i need to append the file with more matrixes

b)The size of the previously calculated matrix does not change, only
the new ones get appended.

c)I just dint want to create a mess of files on the output folder as i
already have a lot of them. Moreover there will be hundreds or
thousands of matrixes, so it will be messy to create so many files.
There is no such rule, if we can avoid that mess.

d) the data need not to be persistent. program needs it, it need not
mean anything to user.

I admit that am not a good programmer, please see it from my
prospective. Thank you and sorry again for my bad english. Thank you.

Sandeep

Ok, here is a suggestion:
For each matrix in the file, keep the point where it starts and where it
ends in the file as a vector of pairs. Whenever you add a matrix to the
file, record the current length of the file as the start position of the
new matrix, write the matrix to the file, record the new length as the end
position for that matrix.

When you need to pull a matrix into memory, retrieve its start and end
positions from the vector that you keep, use seek() to jump to the start
poition in the file, and read the matrix from there.

Best

Kai-Uwe Bux
Nov 22 '05 #8
Hi Kai,

Thank you for your suggestion. At present i have implemented the code
in a very ugly way, with out using seek function. As you said, i tried
to implement the procedure using tellg() and seekg()... but the file
pointer was reading garbage values. I know i am wrong with the code
somewhere , but as i said, i am new to cpp programing, may be i was
wrong with the syntax. can u provide me with a sample program where
seek function is implemented the way you have suggested me to. If i
could use these functions , then my program looks good and less messy .
Thank you once again for your suggestion and help .

Sandeep chandra

Nov 23 '05 #9
Hey john,

Your idea of implementing with two files and using one as index to
other sounds very intresting. Can you please explain me in detail about
the procedure. Also please consider me as a newbie with little
knowledge about programming. Please reply as soon as possible. Thank
you

Sandeep Chandra

Nov 23 '05 #10

"sandeep chandra" <sa***************@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi Kai,

Thank you for your suggestion. At present i have implemented the code
in a very ugly way, with out using seek function. As you said, i tried
to implement the procedure using tellg() and seekg()... but the file
pointer was reading garbage values. I know i am wrong with the code
somewhere , but as i said, i am new to cpp programing, may be i was
wrong with the syntax. can u provide me with a sample program where
seek function is implemented the way you have suggested me to. If i
could use these functions , then my program looks good and less messy .
Thank you once again for your suggestion and help .

Sandeep chandra


How about posting the code you have, so we can help you see where it's
wrong?

-Howard
Nov 23 '05 #11
sandeep chandra wrote:
Hey john,

Your idea of implementing with two files and using one as index to
other sounds very intresting. Can you please explain me in detail about
the procedure. Also please consider me as a newbie with little
knowledge about programming. Please reply as soon as possible. Thank
you

Sandeep Chandra


One file stores the arrays. Very simple flat file.

The other index file stores all the information needed to lookup an
array, for instance it could store the array 'name', maybe the array
bounds, and crucially it stores the offset in the first file where the
array is stored. The index file is small enough that it can be saved in
memory, you would only need to write it out to file when your program
exits. Also the index file is sorted by name for fast lookup (that's why
it's an index).

john
Nov 23 '05 #12
sandeep chandra wrote:
Hi Kai,

Thank you for your suggestion. At present i have implemented the code
in a very ugly way, with out using seek function. As you said, i tried
to implement the procedure using tellg() and seekg()... but the file
pointer was reading garbage values. I know i am wrong with the code
somewhere , but as i said, i am new to cpp programing, may be i was
wrong with the syntax. can u provide me with a sample program where
seek function is implemented the way you have suggested me to. If i
could use these functions , then my program looks good and less messy .
Thank you once again for your suggestion and help .

Sandeep chandra


Here is the basic idea. I hope this gets you started:

#include <fstream>
#include <vector>
#include <string>

template < typename T >
class indexed_file {

typedef std::fstream buffer_type;
typedef buffer_type::pos_type pos_type;
typedef std::vector< pos_type > pos_vector;

public:

typedef pos_vector::size_type size_type;
typedef T value_type;

private:

mutable buffer_type file;
pos_vector pos;

public:

indexed_file ( char const * file_name )
: file ( file_name, std::ios::trunc | std::ios::in | std::ios::out )
{}

~indexed_file ( void ) {}

value_type operator[] ( size_type where ) const {
file.rdbuf()->pubseekpos( pos[ where ] );
value_type result;
file >> result;
return result;
}

void push_back ( T const & t ) {
pos.push_back( file.rdbuf()->pubseekoff( 0, std::ios::end ) );
file << t << ' ';
}

size_type size ( void ) const {
return ( pos.size() );
}

};

#include <iostream>

typedef indexed_file< std::string > wordlist;

int main ( void ) {
wordlist file ( "hello.txt" );
file.push_back( "mother" );
file.push_back( "father" );
file.push_back( "kid" );
file.push_back( "sister" );
for ( wordlist::size_type i = 0; i < file.size(); ++ i ) {
std::cout << file[i] << '\n';
}
}

In order to apply this to your matrix problem, you need to make stream i/o
via operator>> and operator<< work for your matrices.
Hope this helps

Kai-Uwe Bux
Nov 26 '05 #13
Thank you for your help. This part of code must be useful to me for
understanding many things in c++. Thank you all for your help.

Sandeep
Kai-Uwe Bux wrote:
sandeep chandra wrote:
Hi Kai,

Thank you for your suggestion. At present i have implemented the code
in a very ugly way, with out using seek function. As you said, i tried
to implement the procedure using tellg() and seekg()... but the file
pointer was reading garbage values. I know i am wrong with the code
somewhere , but as i said, i am new to cpp programing, may be i was
wrong with the syntax. can u provide me with a sample program where
seek function is implemented the way you have suggested me to. If i
could use these functions , then my program looks good and less messy .
Thank you once again for your suggestion and help .

Sandeep chandra


Here is the basic idea. I hope this gets you started:

#include <fstream>
#include <vector>
#include <string>

template < typename T >
class indexed_file {

typedef std::fstream buffer_type;
typedef buffer_type::pos_type pos_type;
typedef std::vector< pos_type > pos_vector;

public:

typedef pos_vector::size_type size_type;
typedef T value_type;

private:

mutable buffer_type file;
pos_vector pos;

public:

indexed_file ( char const * file_name )
: file ( file_name, std::ios::trunc | std::ios::in | std::ios::out )
{}

~indexed_file ( void ) {}

value_type operator[] ( size_type where ) const {
file.rdbuf()->pubseekpos( pos[ where ] );
value_type result;
file >> result;
return result;
}

void push_back ( T const & t ) {
pos.push_back( file.rdbuf()->pubseekoff( 0, std::ios::end ) );
file << t << ' ';
}

size_type size ( void ) const {
return ( pos.size() );
}

};

#include <iostream>

typedef indexed_file< std::string > wordlist;

int main ( void ) {
wordlist file ( "hello.txt" );
file.push_back( "mother" );
file.push_back( "father" );
file.push_back( "kid" );
file.push_back( "sister" );
for ( wordlist::size_type i = 0; i < file.size(); ++ i ) {
std::cout << file[i] << '\n';
}
}

In order to apply this to your matrix problem, you need to make stream i/o
via operator>> and operator<< work for your matrices.
Hope this helps

Kai-Uwe Bux


Nov 26 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Zaan | last post by:
www.entropy.ch release for Mac OS X.] Hello, My issue is the following: to promote consistency on a site I'm building, I decided to go for a php scheme where some recurring elements...
8
by: Cherrish Vaidiyan | last post by:
hello googles, I have a small sqlplus problem. i have created a table with date field along with other varchar2,number etc. But unfortunately i made a mistake in entering the date. for some date...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: Mark | last post by:
the Following bit of code doesn't work. It seems to respond to the second, starting with 'add iif statement for Good Practice', but not to the first, starting 'add iif statement for archived' ...
4
by: clintonG | last post by:
Using the process class requires the administrator role. Thus, if I may presume, there are other classes that require role-based dependencies. Does anybody know of documentation listing...
2
by: toiletgraffiti | last post by:
this may sound like a crazy question but ive read elswhere that you can remove the dependency for the .net framework by editing the .msi file. is this true?? ive created an ultra simple app to...
17
by: ApexData | last post by:
Hello I have a single form, and want to require the user to make a selection from a serialnumber ComboBox before being allowed to enter any other textboxes. Also, the user should be allowed to...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
15
by: Bob Johnson | last post by:
I have a base class that must have a member variable populated by, and only by, derived classes. It appears that if I declare the variable as "internal protected" then the base class *can*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.