473,411 Members | 2,009 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,411 software developers and data experts.

Ragged array whose rows are of varying size

er
Hi All,

I have an array

x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
..
..
..
xm0,xm1,xm2,...,xmKm

m is *fixed*,
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*
each row is modified *often* by the transform algorithm

does std::vector<vector<some type seem fine? or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?

Thanks.
Jul 4 '08 #1
8 2820
On Jul 4, 2:25*pm, er <erwann.rog...@gmail.comwrote:
Hi All,

I have an array

x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
.
.
.
xm0,xm1,xm2,...,xmKm

m is *fixed*,
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*
each row is modified *often* by the transform algorithm

does *std::vector<vector<some type seem fine? or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?
It is not really possible to tell from "an efficiency
standpoint" which will be superior. It will depend on
many details of such things as object size, how often
they get moved, how often you index in, how difficult
it is to make copies, how your compiler and library
version arrange things, how your platform arranges
memory and handles paging and on and on.

The usual correct answer when efficiency is an issue
(or any resource) is to work up a test case that is as
similar to your production environment and cases as
you can manage. Work it up with both possible ways of
doing things. And get out your stopwatch and do some
tests. If it is other resources, try it both ways and
see how those other resources are used.

If the difference winds up being unimportant, then do
it whichever way makes program complexity easier to
manage.
Socks
Jul 4 '08 #2
er
On Jul 4, 2:25 pm, er <erwann.rog...@gmail.comwrote:
Hi All,

I have an array

x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
.
.
.
xm0,xm1,xm2,...,xmKm

m is *fixed*,
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*
each row is modified *often* by the transform algorithm

does std::vector<vector<some type seem fine? or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?

Thanks.
ps:
typical values: m<10
typical values for K0,...,Km: 100, 1000

Jul 4 '08 #3
er
On Jul 4, 2:44 pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
On Jul 4, 2:25 pm, er <erwann.rog...@gmail.comwrote:
Hi All,
I have an array
x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
.
.
.
xm0,xm1,xm2,...,xmKm
m is *fixed*,
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*
each row is modified *often* by the transform algorithm
does std::vector<vector<some type seem fine? or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?

It is not really possible to tell from "an efficiency
standpoint" which will be superior. It will depend on
many details of such things as object size, how often
they get moved, how often you index in, how difficult
it is to make copies, how your compiler and library
version arrange things, how your platform arranges
memory and handles paging and on and on.

The usual correct answer when efficiency is an issue
(or any resource) is to work up a test case that is as
similar to your production environment and cases as
you can manage. Work it up with both possible ways of
doing things. And get out your stopwatch and do some
tests. If it is other resources, try it both ways and
see how those other resources are used.

If the difference winds up being unimportant, then do
it whichever way makes program complexity easier to
manage.
Socks
sure, i agree with everything you said, and that's probably what i'll
end up doing.
however, i'd be interested to know the sort of things that come into
play in
determining the tradeoff between std::vector<std::vectorvs
std::vector<boost::shared_ptr<vector>>

for example, what happens
- when i write on array[row j]?
- when i resize array[row j]? is there any memory reallocation for the
rows that aren't j. i would think not, but i'm no expert.

ps2: the x's are scalars (say double).


Jul 4 '08 #4
On Jul 4, 11:25*am, er <erwann.rog...@gmail.comwrote:
Hi All,

I have an array

x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
.
.
.
xm0,xm1,xm2,...,xmKm

m is *fixed*,
Using a vector for the rows should be fine then (the outer vector
below), because the number of rows never change.
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*
Using a vector for each row is fine too.
each row is modified *often* by the transform algorithm
vector for rows is still fine.
does *std::vector<vector<some type seem fine?
Yes.
or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?
The one with shared_ptr could be unnoticably slower because of the
extra indirection through the shared_ptr. The vector<vectoruses
indirection anyway: sizeof(vector<some_type>) should be constant
regardless of the size of the vector.

If anything, a vector of vector of shared_ptr could make a difference

vector<vector<shared_ptr<some_type >

if some_type is very expensive to copy or noncopyable. In that case
you may want to consider boost::ptr_vector as well:

vector<ptr_vector<some_type

Ali
Jul 4 '08 #5
er
On Jul 4, 3:02 pm, acehr...@gmail.com wrote:
On Jul 4, 11:25 am, er <erwann.rog...@gmail.comwrote:
Hi All,
I have an array
x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
.
.
.
xm0,xm1,xm2,...,xmKm
m is *fixed*,

Using a vector for the rows should be fine then (the outer vector
below), because the number of rows never change.
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*

Using a vector for each row is fine too.
each row is modified *often* by the transform algorithm

vector for rows is still fine.
does std::vector<vector<some type seem fine?

Yes.
or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?

The one with shared_ptr could be unnoticably slower because of the
extra indirection through the shared_ptr. The vector<vectoruses
indirection anyway: sizeof(vector<some_type>) should be constant
regardless of the size of the vector.

If anything, a vector of vector of shared_ptr could make a difference

vector<vector<shared_ptr<some_type >

if some_type is very expensive to copy or noncopyable. In that case
you may want to consider boost::ptr_vector as well:

vector<ptr_vector<some_type

Ali
excellent! thanks!
Jul 4 '08 #6
In article <b19109c9-ea8d-403a-809a-35b8760a6346
@d45g2000hsc.googlegroups.com>, er***********@gmail.com says...
Hi All,

I have an array

x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
.
.
.
xm0,xm1,xm2,...,xmKm

m is *fixed*,
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*
each row is modified *often* by the transform algorithm

does std::vector<vector<some type seem fine? or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?
Since you're not changing the number of rows, there's no particularly
good reason to use a column of pointers -- you'd do that to avoid
copying entire rows when the row vector is resized.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 4 '08 #7
er
On Jul 4, 3:32 pm, Jerry Coffin <jcof...@taeus.comwrote:
In article <b19109c9-ea8d-403a-809a-35b8760a6346
@d45g2000hsc.googlegroups.com>, erwann.rog...@gmail.com says...
Hi All,
I have an array
x00,x01,x02,...,x0K0
x10,x11,x12,...,x1K1
.
.
.
xm0,xm1,xm2,...,xmKm
m is *fixed*,
each of K0, K1,...,Km is occasionally changed i.e. each row is
"resized" *occasionally*
each row is modified *often* by the transform algorithm
does std::vector<vector<some type seem fine? or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?

Since you're not changing the number of rows, there's no particularly
good reason to use a column of pointers -- you'd do that to avoid
copying entire rows when the row vector is resized.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Absolutely, just wanted it confirmed, just in case. thanks!
Jul 5 '08 #8
On Fri, 4 Jul 2008 12:02:25 -0700 (PDT), acehreli@...com wrote:
>Using a vector for the rows should be fine then (the outer vector
below), because the number of rows never change.
.... if you use reserve() before populating the vector to avoid the
unnecessary copying of elements.
>or is any reason to
prefer
std::vector<std::shared_ptr<vector<some typefrom an efficiency
standpoint?

The one with shared_ptr could be unnoticably slower because of the
extra indirection through the shared_ptr. The vector<vectoruses
indirection anyway: sizeof(vector<some_type>) should be constant
regardless of the size of the vector.
shared_ptr uses one dynamic allocation per element. This will slow
down the applicaton, not the 'extra indirection'.

--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jul 5 '08 #9

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

Similar topics

1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
1
by: Andrew | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hi This VB script prints out a ragged VB array public function display(vbreply) For I = LBound(vbreply) To UBound(vbreply)...
19
by: David | last post by:
Hi all, A while back I asked how to sort an array of strings which would have numerals and I wanted to put them in sequential numerical order. For example: myArray = "file1"; myArray =...
7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
4
by: Ovid | last post by:
Hi all, I'm having a problem trying to create a 2D array whose dimensions are determined at runtime. Below my signoff is a minimal test case that hopefully demonstrates what I'm trying to do. ...
6
by: Anjali | last post by:
Hi, I am handling an array with a hexadecimal index for the first time. What actually does the below means. arr = { '@','£','$','@','@','@','@','@','@','@', 10,'@', 13,'@','@','@',...
8
by: Ray D. | last post by:
I'm trying to write a C function to compute the compressed row storage (CRS) vectors of a 2-d matrix. This is used primarily for increasing computing efficiency of matrices whose main elements are...
30
by: ggnguser | last post by:
It's part of a test and I'm stumped. There is a function void foo(char **x) The function signature is given and cannot be changed, so no passing of other values. The test case involves...
5
by: Stepheno | last post by:
Hi, I am a recently converted Iseries (AS/400) RPG programmer trying to learn HTML/CSS/JavsScript all at the same time (not fun). My problem deals mostly with CSS. I will be reveiving a table,...
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: 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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.