Hi there,
Can somebody explain me how can i use matrixes with dinamic memory? I
use malloc and free (NOT new & delete). I want to access to the matrix
like Matrix[r][c] but i don't know how to do that with pointers and
malloc & free...
If I declare 4 statics matrixs of 576x720, the program brokes down (how
is it posible!?), so i must use dinamic memory (i suppose)...
Can somebody help me?
Txs a lot! ;)
Good luck for all time 3 2525
The usual way to implement [][] syntax is something like this:
class Row
{
public:
int& operator[]( int colIndex );
int operator[]( int colIndex ) const;
private:
// some collection of data (vec/deq)
};
class Matrix
{
public:
Row& operator[]( int rowIndex );
const Row& operator[]( int rowIndex ) const;
private:
// some collection of Row object (eg. std::vector or std::deque)
};
Jose Garcia wrote: Hi there,
Can somebody explain me how can i use matrixes with dinamic memory? I use malloc and free (NOT new & delete). I want to access to the matrix like Matrix[r][c] but i don't know how to do that with pointers and malloc & free...
If I declare 4 statics matrixs of 576x720, the program brokes down (how is it posible!?), so i must use dinamic memory (i suppose)...
Can somebody help me?
Txs a lot! ;) Good luck for all time
Jose Garcia wrote: Can somebody explain [to] me how can I use matrixes with dinamic memory? I use malloc and free (NOT new & delete). I want to access to the matrix like Matrix[r][c] but I don't know how to do that with pointers and malloc & free.
If I declare 4 static matrices of 576x720, the program breaks down (How is it possible?) So I must use dinamic memory (I suppose).
Try increasing the stack size limit first.
Can somebody help me?
Try using a matrix class library.
Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library http://www.netwood.net/~edwin/svmtl/
Then, take a look at
The Object-Oriented Numerics Page http://www.oonumerics.org/oon/
> Can somebody explain [to] me how can I use matrixes with dinamic
memory? I use malloc and free (NOT new & delete). I want to access to the matrix like Matrix[r][c] but I don't know how to do that with pointers and malloc & free.
If I declare 4 static matrices of 576x720, the program breaks down (How is it possible?) So I must use dinamic memory (I suppose).
Use a class who's operator[] returns a pointer to the type.
Example:
template < class T>
class dynamic_2d_arra y
{
public:
dynamic_2d_arra y(int row, int col):m_row(row) ,m_col(col),
m_data((row!=0& &col!=0)?new T[row*col]:NULL){}
dynamic_2d_arra y(const
dynamic_2d_arra y&src):m_row(sr c.m_row),m_col( src.m_col),
m_data((src.m_r ow!=0&&src.m_co l!=0)?new T[src.m_row*src.m _col]:NULL){
for(int r=0;r<m_row;++r )for(int c=0;c<m_col;++c ) (*this)[r][c] =
src[r][c];
}
~dynamic_2d_arr ay(){if(m_data) delete []m_data;}
inline T* operator[](int i) {return (m_data + (m_col*i));}
inline T const*const operator[](int i) const {return (m_data +
(m_col*i));}
protected:
dynamic_2d_arra y& operator=(const dynamic_2d_arra y&);
private:
const int m_row;
const int m_col;
T* m_data;
};
For more information, check out the following link: http://www.tek-tips.com/faqs.cfm?fid=5575 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dddddd |
last post by:
i need do create simple dinamic site - built mainly
of pictures(they are the only dinamic part).
pictuers differ by the -Location- and by -Time- (in which
they were taken)... so on the index page visitor
should have 2 choices (how the pictures will be arranged)
(1) by time
(2) by location
the webmaster will only copy the pictures in folder
|
by: Roberto Dias |
last post by:
I'm a newbie in C++ programming. I bought a book yet and I have
learned by means internet donwloadble materials. I feel not
confortable using multi-dimensional arrays. I simply cannot understand
memory allocation principle. I have got some ideas that require this
one, but only thoughts and no action I have done. Unfortunately, the
Deitel book don't explore this topic well. Vectors? How to use them
insted of multi-dimensional arrays? What...
|
by: gp |
last post by:
Hi all,
I'm using Microsoft Visual C++ 6.0,
I would like to see, debugging my project, all the elements of my dinamic
objects....
I have a dinamic array and a STL vector and I need to know the fields values
at a specific position, but in the Watch windows I can only see the first
element...
|
by: LumisROB |
last post by:
Is it possible to create matrixes with vector <vector <double >> ? If
it is possible which is the element m23 ?
You excuse but I am not an expert
Thanks
ROB
|
by: Jose Garcia |
last post by:
Hi there,
Can somebody explain me how can i use matrixes with dinamic memory? I
use malloc and free (NOT new & delete). I want to access to the matrix
like Matrix but i don't know how to do that with pointers and
malloc & free...
If I declare 4 statics matrixs of 576x720, the program brokes down (how
is it posible!?), so i must use dinamic memory (i suppose)...
| |
by: KinGPIN |
last post by:
hi ; I have a homework about CMatrix; and i had a problem ;in my
homowork i hace functions and operators written for CMatrix class(this
was my first homework); it is wanted to inherite the functions in
CMatrix for CTriangular matrix ;and then inherite the CTriangular
matrix as upper and lower triangular matrixes.In addition ;in the
homework zero elements of matrixes will not be stored to use the memory
efficiently;for example a diagonal...
|
by: javuchi |
last post by:
I just want to share some code with you, and have some comments and
improvements if you want.
This header file allocates and add and delete items of any kind of data
from a very fast array:
#include <stdlib.h>
#ifndef __LIST_H__
#define __LIST_H__
|
by: eriwik |
last post by:
I'm working on an application that performs calculations on triangles
of a 3D-model. As part of those computations I have to calculate a
value for each pair of triangles and the number of triangles can be
quite large (testmodel has 16500 triangles). Each triangle has a
ID-number, however the number-range does not start from 0 but usually
somewhere in the range of 10000-100000 and are not neccesarily
contigious. My problem is to store the...
|
by: ishakteyran |
last post by:
hello to all.. i have a realy tough assignment which requires me to add, substract, multiply, and get inverse of non-sparse and sparse matrixes..
in a more clear way it wants me to to the operations listed above between two sparse, or non-sparse or a sparse and a non-sparse matrix..
for the operations an the matrixes of same kind, say sparse matrix, it seems rather easy .. but what makes me cobfuse is how to operate a sparse with a...
|
by: berte |
last post by:
what's wrong this code ?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct{
char *name;
int no;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |