|
|
Memory allocating/deallocating using functions
Hi,
Can someone tell me how to remove the conflicts here ?
#include <stdlib>
static char*** Memory2DStr(int R, int C);
static void MemoryFreeStr(int C, char*** array);
void main() {
unsigned char ***arr_scenes=NULL;
int R = 15;
int C = 15;
arr_scenes = Memory2DStr(nscenes,2);
MemoryFreeStr(2,arr_scenes);
}
static
char*** Memory2DStr(int R, int C) {
char*** array;
int i;
array = calloc(C,sizeof(char **));
if(array == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
exit(EXIT_FAILURE);
}
for (i = 0; i < C; i++) {
array[i] = calloc(R,sizeof(char*));
if(array == NULL) { // Memory for the Col
fprintf(stderr, "Failed to allocate memory\n");
exit(EXIT_FAILURE);
}
}
return array;
}
static
void MemoryFreeStr(int Col, char*** array) {
int i;
for (i = 0; i < 15; i++) {
free((*array)[i]);
}
free(*array);
}
Thanks,
Sheldon
|
|
0
|
|
|
|
Reply
|
shejo284 (227)
|
11/17/2006 2:16:41 PM |
|
In article <1163773001.360593.126270@h54g2000cwb.googlegroups.com>,
Sheldon <shejo284@gmail.com> wrote:
>Can someone tell me how to remove the conflicts here ?
I don't konw what you mean by "conflicts", but you could start by:
- including <stdlib.h> instead of <stdlib>
- include <stdio.h>
- declaring main() properly
- declaring nscenes
- sorting out your "char ***" and "unsigned char ***"
and then you should consider what those unused R and C variables in
main are for.
Of course, you could have got all of that from reading your compiler's
error messages.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
|
|
0
|
|
|
|
Reply
|
richard91 (3683)
|
11/17/2006 2:27:41 PM
|
|
Sheldon said:
> Hi,
>
> Can someone tell me how to remove the conflicts here ?
>
> #include <stdlib>
Start by making this <stdlib.h> rather than <stdlib>
> static char*** Memory2DStr(int R, int C);
> static void MemoryFreeStr(int C, char*** array);
>
> void main() {
Continue by getting the return type of main right.
When you've learned those two important lessons, come on back.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
|
|
0
|
|
|
|
Reply
|
invalid171 (6556)
|
11/17/2006 2:32:31 PM
|
|
|
2 Replies
31 Views
(page loaded in 0.042 seconds)
Similiar Articles: Allocating, Deallocating and Reallocating - comp.lang.fortran ...If the array is at the end of allocated memory it can usually be increased in place. Using a single ... You never have to allocate, reallocate, or deallocate memory Allocating Memory in DOS - comp.lang.asm.x86You need to basically free up what you're not using (starting from your PSP) BEFORE you can use the memory allocation functions from DOS. ===== For LAN/WAN Protocol ... Allocating memory for Option ROM during BIOS POST and bootloader ...... start, will the os bootloader overwrite the conventional memory allocated using ... that that memory doesn't get used is to hook to all BIOS functions that enumerate memory ... System-API to get current process memory usage for C/C++ pgm ...I'm trying to write unit tests to make sure that my memory allocation processes (for Boost "smart pointers") are actually deallocating correctly after thousands of ... strndup: RFC - comp.compilers.lccIn general, some functions allocate resources, and other functions deallocate those ... program I know has functions using arguments, and dynamic memory allocation is a ... How to check whether malloc has allocated memory properly in case ...How to check whether malloc has allocated memory properly in case if malloc(0) can ... were interpreted in > the way that they were then - unlike with impure functions ... Allocatable versus automatic arrays - comp.lang.fortran... statements using V end subroutine using_V subroutine kill_U deallocate(U ... that with dynamically or statically allocated virtual memory. If you were using ... STL allocators, global new/delete using the heap and shared memory ...... to allocate memory for its objects using shared memory ... If all it is doing is allocating from shared memory instead of ... std::cout << "I am being used to deallocate ... Questions regarding derived data types with allocatable arrays ...... my_type array1 variables without getting a memory leak? i.e.: Deallocating ... Variables type (my_type) :: this if(allocated(this%array1))then deallocate ... How to allocate memory for an array of more than 2G - comp.lang ...One of the best ways to fragment is to allocate/copy/deallocate ever increasing ... Can I use AllocHGlobal to allocate more than 2GB of memory? ... much memory is allocated ... Memory allocation - Rosetta Codedelete [] p2; // deallocate it} Note that memory allocated with C allocation functions (malloc, calloc, realloc) must always be deallocated with free, memory allocated with ... can you allocate the memory using malloc() in C and deallocate the ...... using malloc() in C and deallocate the same memory using ... of the class (members, functions etc), as is the case of a struct. This follows the C style of memory allocation ... 7/7/2012 9:42:22 PM
|
|
|
|
|
|
|
|
|