Memory allocation via malloc et al. is from the heap, which is an area of memory allocated to the program at startup and the location of which you cannot predict nor specify (normally) when you write the program.
Are you actually needing to
allocate memory in that particular segment? Or are you really talking about having to set a pointer to point to a particular physical address?
For a flat memory model (eg, an ARM processor), we memory-mapped our FPGA hardware registers to start at a specific memory address thus:
Code:
#define FPGA_BASE (0x00C00000)
#define patFPGABASE ((STRUCTFPGA*)FPGA_BASE)
// STRUCTFPGA was previously defined as a struct whose elements are the hardware registers
From that point on, patFPGABASE is used as a pointer to those registers. Of course, we could have just as easily declared a pointer variable and assigned the starting address to it:
Code:
#define FPGA_BASE (0x00C00000)
STRUCTFPGA* patFPGABASE;
patFPGABASE = (STRUCTFPGA*)FPGA_BASE;
Judging from your reference, "memory in particular segment", you are programming on an Intel machine under Windows. In that case, Microsoft Visual C++ provides a function macro, MK_FP, to "make a far pointer":
Quote:
From the VC++ 1.52 Help on MK_FP:
_MK_FP
#include <dos.h>
Syntax void __far *_MK_FP( unsigned seg, unsigned offset );
Parameter Description
seg Segment value for pointer
offset Offset value for pointer
The _MK_FP macro makes a far pointer from the segment value, seg, and the offset value, offset.
Return Value
The _MK_FP macro returns the resulting far pointer. |
This was under Win16. There might be more support for this under Win32.
Of course, if you are trying to do something entirely different, then please describe it and mention what system (OS & C development environment).