473,379 Members | 1,530 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,379 software developers and data experts.

suggestions on improving source

As part of a struct called 'overall', I have a two dimensional array
(ipd) and one dimensional array (mpt) that I'll merge - to produce an
end result that akin to the chart shown. The end result is stored in a
vector of 'storables'.
The code compiles and excutes. The question. Interested in
improvements or perhaps a more efficient way than what I've shown.
Thanks in advance.

# include <vector>
# include <iostream>
# include <algorithm>
#include <fstream>

using std::cout;
using std::endl;
using std::vector;
using std::ostream;

enum proc_type { FFT, IFFT, INVALID = -1 };

struct data_segment_id_t {
int segment_id;
data_segment_id_t()
: segment_id(-1) {}
};

unsigned int const max_seg = 5;
unsigned int const max_proc = 6;
unsigned int const max_recipients = 7;
unsigned int const max_processors = 5;

struct im_def {
data_segment_id_t sid;
unsigned int tp_data_size;
unsigned int rp_data_size;
im_def()
: tp_data_size(0)
, rp_data_size(0) {}
};

struct my_proc_t
{
data_segment_id_t seg_arr[max_seg];
proc_type pt ;
my_proc_t()
: pt (INVALID)
{}
};

struct overall { // this is filled out in main - below.
my_proc_t mpt[ max_proc ];
im_def ipd[ max_seg][ max_processors ];

};
/*
In main (below) I've filled out the structs in overall as follows:

im_def
sid | tp_data_size | rp_data_size
--------------------------------------------------
[0][0] 0 | 0x100 | 0x200
[1][0] 3 | 0x200 | 0x200
mpt
sid | pt
------------------------------------
0, 1, 2 | FFT
3 | IFFT

I will combine the mpt and im_def such that the end result will be:

end_result
sid | pt | tp_data_size | rp_data_size |
tp_offset | rp_offset

--------------------------------------------------------------------------------------
(*) 0 | FFT | 0x100 | 0x200 |
(**)0xC000000 | (**) 0xF000000
1 | IFFT | 0x200 | 0x200 |
(***)0xC000100 |(***) 0xF000200

Couple things:
(*) ipd is a two dimensional array. For simplicity I'm only
doing the [0][0]
and [1][0]. You will compare mpt-sid with im_def-sid. if
there's a match.
I will store sid, pt, tp_data_size, rp_data_size, tp_offset and
rp_offset
(see end result above)
(**) is the initial tp and rp offsets.
(***) is the result of adding - for tp 0xC000000 + 0x100
- for rp 0xF000000 + 0x200

*/
class Storable
{

private:
int sid;
proc_type pt;
unsigned int tp_data_size;
unsigned int rp_data_size;
unsigned int tp_offset;
unsigned int rp_offset;

static unsigned int tp_offset_glob;
static unsigned int rp_offset_glob;

public:
Storable(
int sidIn,
proc_type ptIn,
unsigned int tpIn,
unsigned int rpIn
)
: sid(sidIn)
, pt(ptIn)
, tp_data_size(tpIn)
, rp_data_size(rpIn)
, tp_offset(tp_offset_glob)
, rp_offset(rp_offset_glob)
{
tp_offset_glob+=tp_data_size;
rp_offset_glob+=rp_data_size;
}

friend ostream &operator<< (ostream &os, const Storable s)
{
os << std::dec << s.sid << " " << s.pt << " "
<< std::hex << s.tp_data_size << " " << s.rp_data_size
<< " " << s.tp_offset << " " << s.rp_offset << endl;
return os;
}
};
unsigned int Storable::tp_offset_glob=0xC000000; // known initial value
unsigned int Storable::rp_offset_glob=0xF000000; // known initial value

// requirements are here in foo_w
class foo_w
{
private:
vector<Storable> v;
public:
foo_w(const overall ov)
{

/*
1.
I'll get an overall from the constructor - I'll create
end_results -
using a storable class with a suitable container.
This way, I'll have everything when I iterate through the container
*/
for(int i=0;i<max_seg;i++)
{
for(int j=0;j<max_processors;j++)
{
// I consider im_defs with zero rp and zero tp as unused. It
would be better
// to default the segment_id to -1 in order do distinguish
between unused and
// empty im_def's - perhaps
if(ov.ipd[i][j].tp_data_size !=0 || ov.ipd[i][j].rp_data_size != 0
)
{
// Found a used im_def now search a matching mpt.
for(int k=0;k<max_proc;k++)
{
// Search only valid my_proc_t's
if(ov.mpt[k].pt != INVALID)
{
for(int l=0;l<max_seg;l++)
{
// Notice that I'm doing full walks of ther array here, if the
array is
// only used in a sequential order (e.g. only the first n
elements breaks
// should be inserted in order to optimize the code - I think
if(ov.mpt[k].seg_arr[l].segment_id != -1 &&
ov.mpt[k].seg_arr[l].segment_id ==
ov.ipd[i][j].sid.segment_id)
{
// Gotcha
v.push_back(Storable(ov.mpt[k].seg_arr[l].segment_id,
ov.mpt[k].pt,
ov.ipd[i][j].tp_data_size,
ov.ipd[i][j].rp_data_size));
}
}
}
}
}
}
}
}

void dump()
{
// iterate and print stuff here.
for(vector<Storable>::iterator it=v.begin();it!=v.end();it++)
{
cout << *it;
}
}
~foo_w() {}
};

int main()
{
overall ov;

ov.ipd[0][0].sid.segment_id = 0;
ov.ipd[0][0].tp_data_size = 0x100;
ov.ipd[0][0].rp_data_size = 0x200;
ov.ipd[1][0].sid.segment_id = 3;
ov.ipd[1][0].tp_data_size = 0x200;
ov.ipd[1][0].rp_data_size = 0x200;
ov.mpt[0].seg_arr[0].segment_id = 0;
ov.mpt[0].seg_arr[1].segment_id = 1;
ov.mpt[0].seg_arr[2].segment_id = 2;
ov.mpt[0].pt = FFT;
ov.mpt[1].seg_arr[0].segment_id = 3;
ov.mpt[1].pt = IFFT;

foo_w f(ov); // now transform the c style struct into something
meaningful

f.dump();
}

Jan 20 '06 #1
2 1474
ma740988 wrote:
As part of a struct called 'overall', I have a two dimensional array
(ipd) and one dimensional array (mpt) that I'll merge - to produce an
end result that akin to the chart shown. The end result is stored in a
vector of 'storables'.
The code compiles and excutes. The question. Interested in
improvements or perhaps a more efficient way than what I've shown.
Thanks in advance.

[..]
friend ostream &operator<< (ostream &os, const Storable s)
Didn't you mean to pass by reference?

friend ostream &operator<< (ostream &os, const Storable & s)
{
os << std::dec << s.sid << " " << s.pt << " "
<< std::hex << s.tp_data_size << " " << s.rp_data_size
<< " " << s.tp_offset << " " << s.rp_offset << endl;
return os;
}
};
unsigned int Storable::tp_offset_glob=0xC000000; // known initial value
unsigned int Storable::rp_offset_glob=0xF000000; // known initial value

// requirements are here in foo_w
class foo_w
{
private:
vector<Storable> v;
public:
foo_w(const overall ov)
Top-level 'const' is usually meaningless. Did you mean to pass by
reference again?

foo_w(const overall & ov)
{
[..]


V
Jan 20 '06 #2

Greetings Vic

Top-level 'const' is usually meaningless. Did you mean to pass by
reference again?
I tend to miss out on const correctness at times. Thanks
foo_w(const overall & ov)
{
[..]


V


Jan 20 '06 #3

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

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
15
by: lallous | last post by:
Hello, I have a function like: void fnc() { char *mem1, *mem2, *mem3, *mem4; // lots of code... // mem1, 2, 3, 4 got allocated // lots of code and condition checks if (condition_failed)
8
by: murphy | last post by:
I'm programming a site that displays info from AWS Commerce Service 4.0. At each change of the asp.net application the first load of a page that uses the web service takes 30 seconds. Subsequent...
1
by: Brian Basquille | last post by:
Hello all. Have been working on the Air Hockey game on and off for a couple of weeks now.. but have had plenty of other assignments to keep me busy along with it. But i would like some...
29
by: Olaf Baeyens | last post by:
Because of historical reasons, I have both C# and C++ managed/unmanaged code mixed together in my class library. But I prefer to port code to C# since it compiles faster and the syntax is much...
2
by: Irfan Akram | last post by:
Hi Guys, I am in search of some innovative ideas in improving the interface of Online Marking System. At the moment it has some good functionality, but lacks a professional interface. Is...
47
by: Matthew | last post by:
I am just about finished my first Visual Basic program. Yay! Does anybody had any suggestions about improving the look of the interface? I have read that programmers tend to have a cluttered...
2
by: vasudevram | last post by:
Hi all, I had created this open source project - xtopdf - http://sourceforge.net/projects/xtopdf - some time ago. It's a toolkit to help with conversion of other file formats to PDF. The...
1
by: samadams_2006 | last post by:
Hello, I have Visual Studio 2005 and am developing my first web site. I see TreeViews, ReportViewers, etc. but I'm not sure which approach that I should choose. Let me tell you what I'm going...
10
by: Jo | last post by:
Hi there: I m wondering what can I do to improve my code, everytime I am coding I feel like it could be done better. I started on c# a good months ago and feel conformtable but sometimes I Need...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.