Subj : Re: Questions about large memory allocation...? To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Thu Sep 15 2005 02:10 pm mujeebrm wrote: > unsigned int *p=0,n=0; > p = (unsigned int *) malloc(65535*sizeof(unsigned int ) ); /* this works */ > for(n=0; n<65535; n++) > printf(" %u\n ", *(p+n) ); /* it doesnt show count from 0 but 32768 >onwards, > > why, as such, i want it to start at 0 onwards */ In addition to Mr King's answer... Ordinary pointers (whether far or plain) "wrap" back to 0 at their 64k boundry. In addition, malloc eats the first 4 bytes of the first paragraph, so any pointer you get will definately not be nnnn:0000, but will almost always be nnnn:0004. Thus in a 16bit program, the largest structure is 64k minus 4 bytes. or, (32k-2) ints, or (16k-1) longs. Huge pointers get around this by recalculating the nnnn: portion. Here are a few reasons to _not_ use huge pointers. 1) They are slower than normal pointers. 2) There are quirks to huge pointers in the Borland implementation, so be carefull to check the results, especially in the cells around the 64k boundries.. And, no, you don't need to use the huge memory model to use huge pointers. .