|
One solution is to use a Map for each row.
Another solution is a map < pair<int,int> xy, double distance >
However, I would use the latter only if it's *really* sparse. You could run performance checks against both, but I'd expect the one-map-per-row to be faster still.
OK, breakdown of my previous post (I guess it might have got lost): random index access is fastest with map, row/colum iteration can benefit from another storage scheme.
so you emulate the matrix by a vector < map<int, double=""> * >, and can keep unused rows as NULL pointer.
lookup is them basically:
double GetItem(int row, int col)
{
if (below diag)
return GetItem(above diag);
map<int,double> * rowMap = m_vector[row];
if (rowMap == NULL)
return 0.0;
map<int,double>::iterator it = rowMap->find(col);
if (it == rowMap.end())
return 0.0;
return it->second;
}
I'm still pondering a thought of a "better" storage scheme, however, the map will take you quite far. You can probably boost performance (if required) by a custom pool allocator.
May I asked what you're working on? I've got 5 years of successless physics study in my backlog...
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
We're trying to simulate real-time surface deformation
with possible extension to a collision detection algorithm.
Speed and low memory consumption are therefore very
desirable.
|
|
|
|
|
|
Slow at the moment - we're bug slaying. Our solution
engine is also cranking out correct solutions, but they
are sometimes translated and/or rotated (albiet correct...) .
I therefore haven't had time to code/implement the array
map yet. Soon though...
Let's just say we still have some work to do.
I think it will eventually be a go.
|
|
|
|
|
I am a physicist like you and the problem You have many of us had before.
The goal of the boost project is to provide fast number crunching libraries.
Your matrix can be represented by a sparse matrix which allocates only memory
for the needed elements. You can warp a class around to make use of the symmetry of your matrix.
http://www.boost.org/libs/numeric/ublas/doc/matrix_sparse.htm
Even if you do not like the coding style it is worth the effort. Your approach
with many pointers and arrays with no boundary checking is very error prone and I guarantee you that You will spend much more time with tracking down errors compared to the time you will need to integrate the sparse matrix.
|
|
|
|
|
HI,
I want to create menu item on the top of the modal dialog box so that the if the user clicks on the item it has to show drop down list as File Open, Save As ..etc. Any help would be appreciated.
Thanks
|
|
|
|
|
I have a machine which has a VPN connection and a LAN connection open at the same time. I would like to send and receive through the VPN connection instead of the LAN connection. My application is designed to listen on the IP address returned by gethostname/gethostbyname. I need to modify it to use the static IP address assigned to me for the VPN connection. What changes do I need to make to accomplish this?
On a related note where should I look in the MSDN to programatically start up the VPN connection and wait until the connection is established or an error occurs?
|
|
|
|
|
You need to explicitly bind your socket to a specific IP address (network card) prior to doing the listen.
|
|
|
|
|
I have a dll in which I dynamically create an owner draw button. I created the button with the BS_OWNERDRAW flag, but somehow the DrawItem method is not being called. Anyone has a suggestion about why it is not being called?
|
|
|
|
|
|
|
Anyone knows why am i getting this exception while using ado and what to do ?
Exception thrown for classes generated by #import Code = 8007007e
Code meaning = The specified module could not be found.
Source = (null)
Description = (null)
Thank you !
Also another question ---> which app posts the ado210.chm in the sysyem/ado folder ?
|
|
|
|
|
The error code is returned from LoadLibrary when it either doesn#t dind the DLL to load itself, or some implicitely linked DLL is missing.
When using COMponents, when you create an instance this usually indictaes that a control is registered, but not properly installed (either the physical .dll/.ocx is missing, or it implicitely links to a missing DLL)
If it happens at interface marshaling/QueryInterface, it could be a missing proxy/stub DLL.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
BlackRider wrote:
Also another question ---> which app posts the ado210.chm in the sysyem/ado folder ?
Try (re)installing MDAC (Microsoft Data Access Components), it might be the one which installs the chm file as well.
|
|
|
|
|
Hello,
I have created a binary file in Matlab and i am using it for my C code.
I would like to know how do i procedd, it's a sine wave.
Any DSP specialist in here?
Thx
F.K
|
|
|
|
|
Just out of curiosity, what is DSP?
|
|
|
|
|
DSP = Digital Signal Processor. I think. Unless it has another meaning.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
Digital Signal Processing
|
|
|
|
|
DSP stands for Digital Signal Processing.
I'am an electrical engineering student, that's is why i have weird questions sometimes.
F.K
|
|
|
|
|
|
What do you want to do with it?
I don't use a DSP myself, but I'm interfacing one
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
I don't know if you people are familiar with DSP.
I am processing data and i have several modules, filter low-pass, high pass, equalizer.
I would like know to sample the data (sine wave) i get after the last module.
Hope this explanation brought somehow some light.
F.K
|
|
|
|
|
This worked for me on a project i just finished.
double readDouble(istream& is)
{
char buffer[sizeof(double)];
is.read(buffer,sizeof(double));
return (double)(*(reinterpret_cast<double*>(buffer)));
}
But make sure that the data is in the right order, (big endian / little endian) otherwise you might have to reverse the order of the bytes in the buffer. I'd be interested to know if it works
|
|
|
|
|
Hi,
How does this piece of code works?
double readDouble(istream& is){ char buffer[sizeof(double)]; is.read(buffer,sizeof(double)); return (double)(*(reinterpret_cast(buffer)));}
Sorry,not very familiar with C programming
F.K
|
|
|
|
|
flora_k wrote:
How does this piece of code works?
Simple idea really
1/ read enough data out of the file to rebuild one number
2/ convert that data into a number
Why like this? There are simpler ways, and this isn't safe, in fact its downright ugly, but it's extensible for big endian data.
BTW, this is C++ code. sorry missed that on the first readthrough, you'll probably need to use fopen and fclose to do the file management in C, and the cast to a C-Style cast. Below is a fuller example, might help if you can see it in context
#include <fstream>
#include <iostream>
using namespace std;
double readDouble(istream& is)
{
char buffer[sizeof(double)];
is.read(buffer,sizeof(double));
return (double)(*(reinterpret_cast<double*>(buffer)));
}
int main()
{
ifstream fin("your_filename_here.bin",ios::in|ios::binary);
double data;
int numPoints = 1000;
for(int i = 0; i < numPoints; ++i)
{
data = readDouble(fin);
cout << data << endl;
}
return 0;
}
|
|
|
|