- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For example: Is the following code legal?
Do I need typecast before malloc()?
type (MYTYPE), pointer :: pMyType
pMyType => malloc(SIZEOF(MYTYPE))
Do I need typecast before malloc()?
type (MYTYPE), pointer :: pMyType
pMyType => malloc(SIZEOF(MYTYPE))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page