1st: What do you mean by 'Different Platforms' It's all standard CPP, Standard Libraries, etc. Should work on any machine that supports a CPP Compiler to ISO Standards.
2nd: Does it Work! (I Don't see any obvious errors at a Glance, but a First Glance can be deceiving in this game, which is the reason we do debugging. I am not willing to do that for you, but I'll offer Help if you encounter a Difficulty.)
3rd: What are you trying to prove, apart from that there is more than one way to skin a Cat (or in this case, write a piece of Code) Otherwise, Did you provide a Crude Example of a Bigger Problem, but you are trying to touch the basics, by simplifying the problem, (and sometimes by Abstracting the problem, hiding the real issues that you try to discuss). For Instance, did you abstract the concept of MFC Classes down to Floating Point Variables.
4th: If it all works, Why pose the question in the first place. (In other words, What was the real question!)
You are right, the second method of course works and is my preferred method as long as I do not need a loop to create and delete it, but I have to be careful when sending the array to a function.
Thank you to advise that the first one fits with iso standard.
You seem to have yourself very confused on pointer dereferencing and memory allocation. You are trying to assign "right way" to something that has nothing to do with the language but what is essentially about memory ownership.
Your version 3 is mongrel of a thing and NOT CLASSICAL AT ALL. Look carefully at what it is which is an array of pointers on the stack if within a function or on the heap if globally assigned and into which you place allocated memory. YUCK writing any function via pointer reference to access that abomination would be fun and dangerous it's not necessarily a persistent structure unless defined globally.
So how about I give you 4 WHICH IS ACTUALLY THE CLASSICAL VERSION
//4. The ACTUAL CLASSICAL METHOD
//4.1. Create and Array of pointers:
float **matriz3 = new (float*[YMAX]); // Create an array of pointers
//4.2. Fill each pointer in the array with a allocated pointer to a block of memory:
for (int y = 0; y < YMAX; y++)
matriz3[y] = new float[XMAX];;
// Its derived from the standard C version which looks like this
float **matriz3 = (float**)malloc(YMAX * sizeof(float*)); // Create an array of pointers to a float
for (int y = 0; y < YMAX; y++)
*matriz3[y] = (float*)malloc(XMAX *sizeof(float)); // Fill each pointer array entry
So now you have another one and all of them are perfectly fine within the contexts of what they were designed to do although 3 is of very limited use locally. You would need to take care passing a reference to your version 3. Method 4 is usable anywhere and someone needs to take responsibility to delete/free the allocated memory blocks.
Whats different is 1 and I think 2 allocate all the memory together in one big contiguous block, 3 & 4 don't do that they have a pointer block which points to memory blocks for each row array and those blocks can be all over the place in physical memory. Structurally they are both 2D float arrays but there is differences in there internal memory layout. Versions 3 & 4 will never produce anything that looks like version 1 without a lot of luck with memory allocation.
I won't comment on 2 because I have a feeling it may be compiler dependent C++11 seems to say it will be a contiguous block but I am not sure all compilers will do it if they are not C++11 compliant.
The two structures also do no use the same amount of memory take a 2x2 matrix. Version 1 simply allocates memory for 4 floats. Version 3 & 4 allocate 2 pointers and then 2 floats allocated into each pointer. So if your floats are 4 bytes and your pointers are 4 bytes, version 1 allocates 16 bytes of memory and version 3&4 allocate 8+16=24bytes.
Technically the access to version 1 is faster but it has the considerable downside that as the structure gets larger the chances of finding that amount of contiguous memory block size becomes difficult. Version 3 & 4 can go to much larger size and are more likely to still work at larger sizes that version 1.
So you asked:
Is the first method correct for all the platforms? Yes but that is only one way to make a 2D float array don't expect that to work for other methods on any platform.
Your overloaded functions are correct for 1, 3 & 4 ... I am still wary of 2 you might need to do some checking
//This print method only works for method 1 & 2:
void print_data2d(float *matriz,int ymax,int xmax,char *method);
//This print method only works for method 3 & 4
void print_data2d(float **matriz,int ymax,int xmax,char *method);
There is some danger in that overloading that the use of an "&" will give you the wrong one. Consider a version 1 array and I went to print it.
float *matriz; /// version 1 array
print_data2d (&matriz, .... ); // made a mistake with &
See what happens there .... matriz is a float* .. &matriz is a float** .. so the call takes the second form and probably crashes and burns.
I think for safety you need to do a bit of typecasting
Can I point out that if you really want portability with C++11, we do this and there is nothing your code can do with this as it uses the standard vector library
using namespace std;
#define YMAX 6
#define XMAX 4
// single line to define a 2D array of floats
vector<vector<float>> matrix1(YMAX, vector<float>(XMAX));
// Now you can just set values
matrix1 = 3.6f;
matrix1 = 4.0f;
matrix1 = 8.0f;
// Or read them back
float f = matrix1;
The really cute part is it can be used on any standard type
// single line to define a 2D array of STRINGS
vector<vector<string>> stringmatrix(YMAX, vector<string>(XMAX));
// writing strings in the array
stringmatrix = "hello at 0,0";
stringmatrix = "this one";
stringmatrix = "hello at 5,3";
// Getting string value from the array
string whatdidwesay = stringmatrix;
Increase Baudrate of CSocket and reduce data chunk size while communication.. big data if reduced to small data chunks with sequence added in the data packet may help in faster data transfer across systems.. look in windows provided CSocket for more info
int uwSeq;// sequencing starts from 1 upto 879
int maxSeqCount;// when this reaches 879 reaset to 1
char myData;//Small Chunk
unsigned int uwcrcData;//CRC of uwSeq,myData
send stSmallChunk data packet and validate at other end using CRC recieved seqs.
I am looking for an article about dialing a phone number directly from my database (i.e. as in Call Centre), Via CPP Code. I do not seem to be able to filter the article count down to less than 3700, mostly altogether unrelated. Anyone a Hint or Idea?
It is an MFC42/CPP Desktop Application I want to Auto Dial from, to establish a Voice Connection. I.e.: I want staff to contact selected customers, via de Phone Number we have on our DB. As a Laundrette, we have an issue with customers forgetting they left stuff in. I'm writing an MFC Application for staff to deal with this during quiet times. Automatic dialling helps to prevent mis-dials, and protects our phone bill against misuse.
I am planning to connect Via a "RealTech" Dial up Modem Card, or Equivalent. All my XP Computers have one, or something similar, by a different manufacturer. I also harvested about half a dozen. The Installation software is typically part of WinXP.
The XP Default installation is that specific and unspecified features may not be available. However, I seek only Voice Contact, on an Out Dialling only Connection.
I have also a number of Installation disks for older Real Tech Modems which I bought in the past. I suppose that any and all of them can do a basic Function, Dialling out, and thereafter managing a Voice Based conversation. All Computers we currently have, have also a form of sound processing card.(Very Basic in most cases) I assume that this can be used to get the Voice Aspect realised for a phone connection.
Al I am ultimately interested in is, getting an outgoing Voice Connection.
We have NO requirement at all, to deal with in coming calls.
I Think we are both rumbled by gremlins. My Post was somehow split in two by the CodeProject Server.
Let us Discard One Thread, I Propose This One!
Otherwise: My Reply to This One is:
You must be under pressure, but, I know how that feels. Answered this question before in this thread, However,it is a Desktop Task, in MFC42. I am not looking for a Solution, but for an article(hopefully Old, so that it appreciates the limitations of MFc42) in CodeProject, or elsewhere. Even a Title of a book will do.
(Mental Block I had, not looking for 'Modems' in the first place!), as you know, that's how it goes.
However, it covers, apart from a sprinkling of C or CPP, a Lot of CE, C#, etc, which have their own libraries, etc, and hence are instructive, but not very useful. For Instance, "Phone.Lib" is not a component of MFC42.
All I need to do is the Dialling, and the Channelling of the connection to the Sound System, and hanging up, after ending the call.
I'm going to try for now something called "RasDial.exe" and see how I get on with it. Hopefully I can fool it in not looking for a Phonebook Entry, or stopping it from trying to make an Internet Connection.
I have also bought a £6.00 USB Dialup Modem which comes with a CD. Hopefully the CD contains something useful. I live in hope. Even if it fails, the cost is less than a packet of cigs, and, I still have the Modem.
Hope if all else fails to be able to hang a Head Set and Mike to the 'Phone' Output, and, hope the Modem can do the Dialling via the Line Socket.
May need to set to Pulse, and a switch to isolate the head set, (I know how POTS works) but, for now hope we can make it work without having to resort to this.
Worth Six Pound to try it, though, even if it does not work!
Thanks, and, I'll keep you Posted, but, remember, I'm on my own, and have to resolve many issues, all by myself. If I get an Intractable Problem in One Place, I put it aside, for dealing with, and whilst waiting, tackle something else. That keeps the entire front moving.