![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| far pointer | useless79 | High Level Programming | 1 | 11-08-2007 02:13 AM |
| A Pointer to non-Virtual Address, and All of my Hard drive | xcoder66 | High Level Programming | 9 | 12-19-2005 02:22 PM |
| pointer | sarwan | High Level Programming | 1 | 11-15-2005 03:41 AM |
| How to Achive IP address through MAC(Ethernet) address | krishnacins | IP Networking | 3 | 08-29-2005 05:45 PM |
| network address and broadcast address? | pnxi | UNIX for Dummies Questions & Answers | 7 | 11-10-2003 08:29 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#8
|
|||
|
|||
|
confused?
could you show the entire program? |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
Quote:
Code:
char heap[ 134 ];
char *firstFree = heap;
char *allocMem( int size ) {
if ( size >= 0){
void *malloc(size_t sizeofint);
/*allocate space for an array with size number of elements of type int*/
char * ip = malloc(sizeof(int) * size);
if(ip == '\0'){ /*If function is null, memory not allocated so exit*/
return '\0';
}else{ /*Otherwise return address of first free space*/
firstFree = ip+1;
return firstFree;
}
}
else {
printf("ERROR: Cannot allocate negative memory");
}
return 0;
}
void dumpHeap( void ) {
char letter;
int counter = 0;
int i;
for (i=0; i < *firstFree; i++){
letter = heap[i];
printf ("%c ",(char) letter);
counter++;
if(counter==10){
counter = 0;
printf("\n");
}
}
printf("\n");
}
|
|
#10
|
||||
|
||||
|
for (i=0; i < 134; i++)
You can define some constants or give the dumpHeap() function the size of the heap. You cannot determine length of the array having only a pointer on it's first element |
|
#11
|
|||
|
|||
|
i'm trying to print out the content of the memory from the beginning up till the first free space which i have firstFree to, so i'm kinda trying to print out heap[0] to heap[firstFree address]
|
|
#12
|
||||
|
||||
|
then
for (i=0; heap+i < firstFree; i++) heap+i == &(heap[i]) -pointer to the memory of element i of the heap, it must be less than firstFree |
|
#13
|
|||
|
|||
|
Quote:
*firstFree is only the value of the heap[1]; |
|
#14
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |