home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!zaphod.mps.ohio-state.edu!wupost!gumby!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!prancer.eche.ualberta.ca!niu
- From: niu@prancer.eche.ualberta.ca (Shaohua Niu)
- Subject: Two-dimensional Array
- Message-ID: <1992Nov6.163315.20337@kakwa.ucs.ualberta.ca>
- Sender: news@kakwa.ucs.ualberta.ca
- Nntp-Posting-Host: prancer.eche.ualberta.ca
- Organization: University Of Alberta, Edmonton Canada
- X-Newsreader: Tin 1.1 PL3
- Date: Fri, 6 Nov 1992 16:33:15 GMT
- Lines: 39
-
- I am trying to use dynamic memory allocation for two-dimesional
- matrices and the code fragment is as follows:
-
- typedef float **MATRIX;
-
- MATRIX calloc_matrix(int row, int col)
- {
- int i;
- MATRIX mat;
- mat = calloc(row, sizeof(float *));
- if (mat==NULL) exit(1);
- for (i=0; i<row; i++) {
- mat[i] = calloc(col, sizeof(MATRIX));
- if (mat[i]==NULL) exit(1);
- }
- return mat;
- }
-
- when this is called with row=9 and col=9, the fucntion works for the
- pointer mat[0] to mat[6], but for mat[7], it exited abnormally to DOS,
- with an error message saying memory allocation error, and the DOS
- is halted. It seems that memory allocation of mat[i] is in conflict
- with the operating system codes resides in the memory. Actually this
- piece of code is quite close to the example in the FAQ. But why does
- it not work. I am using Microsoft C/C++ 7.0 under DOS5.0.
-
- Can anybody kindly point out my problem?
-
- Thanx in advance.
-
- --
-
- | ------------------------------------------------------------
- | ---+---- Shaohua Niu |
- / | Dept. of Chem. Eng. | Email: niu@prancer.eche.ualberta.ca
- -----+----- Univ. of Alberta | Phone: (403) 432-7803 (Home)
- | Canada, T6G 2G6 | (403) 492-2971
- | -------------------------------------------------------------
-
-