Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

allocate()

Intel_C_Intel
Employee
764 Views
Hi,

Is there a way to make allocate() used the address starting from a
region boundary(64KB) and end also at region boundary? I don't care it may waste some memory. Or if someone can give me an equivalent code using malloc() to realized allocate().

Thank you so much.
dppvlit
0 Kudos
4 Replies
Steven_L_Intel1
Employee
764 Views
The easy way to do this is to allocate 64KB more than you want and round the returned address up to the next 64KB boundary.

I don't recommend using ALLOCATE for this, as the address computation is not under your control, but using malloc it should be easy enough.

A better bet might be the Win32 API routine VirtualAlloc, passing NULL as the lpAddress argument, since this operates in units of 64KB pages anyway.

Steve
0 Kudos
Intel_C_Intel
Employee
764 Views
I guess I didn't state the problem clearly.
There is a user defined TYPE of allocatable arrays (or pointer). I used allocate() to allocate memory for it. If I used VirtualAlloc, how do I pass the returned address to the pointer or the array so that later references to them behave correctly, just like allocate() does?

Thanks
dppvlit
0 Kudos
Intel_C_Intel
Employee
764 Views
For example: Is the following code legal?
Do I need typecast before malloc()?

type (MYTYPE), pointer :: pMyType
pMyType => malloc(SIZEOF(MYTYPE))
0 Kudos
Steven_L_Intel1
Employee
764 Views
No. You need to do this instead:

type(MYTYPE) :: MyTypeThing

pointer (pMyType, MyTypeThing)

pMyType = malloc(sizeof(MyTypeThing))

Note the use of the non-standard integer pointer feature, not the Fortran 90 POINTER which is different.

Steve
0 Kudos
Reply