- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Re: Size of memory block pointed by a pointer?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2010 03:45 AM
тАО11-08-2010 03:45 AM
Size of memory block pointed by a pointer?
On Linux we can use malloc_usable_size.
On Windows we can use _msize.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2010 04:35 AM
тАО11-08-2010 04:35 AM
Re: Size of memory block pointed by a pointer?
http://forums13.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1289218785071+28353475&threadId=1380264
As far I know there is no such call in VMS/DECC
(searched all decc rtl and starlet includes).
Could You try to explain, why You need it ?
Trying to tweak some few bytes out of an allocated memory structure ?
Maybe a better design of the software would be preferable, if it works without non-standard extensions ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2010 04:56 AM
тАО11-08-2010 04:56 AM
Re: Size of memory block pointed by a pointer?
(not from my own experience, but seen in changelogs of e.g. CVS).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2010 04:57 AM
тАО11-08-2010 04:57 AM
Re: Size of memory block pointed by a pointer?
I have read the UX discussion before opening this thread.
I have also searched the header files.
We have a little piece of software written by one of our linux guys that shall be ported to OpenVMS. It uses this function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2010 05:37 AM
тАО11-08-2010 05:37 AM
Re: Size of memory block pointed by a pointer?
You may want to dig a little bit deeper to see why they use that function. Too lazy/frugal to store their own size or do they want to actually use any 'excess' (alignment) space?
You can probably roll your own if need be.
The malloced size is stored in the addresses before the pointer. A few trials in a debugger session with allocations 1 .. 32 will soon enough show what is going on.
Hein
*Portability*
`malloc', `realloc', and `free' are specified by the ANSI C standard,
but other conforming implementations of `malloc' may behave differently
when NBYTES is zero.
`memalign' is part of SVR4.
`malloc_usable_size' is not portable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2010 08:03 AM
тАО11-08-2010 08:03 AM
Re: Size of memory block pointed by a pointer?
As was already pointed out, there is no portable way of doing it.
On VMS, you can intercept calls to malloc() by compiling with /pref=except=malloc and providing your own malloc, as shown below. If you write in C++ and do allocations using new expression, you can override global operator new.
-Boris
$ cc/pref=except=malloc x.c
$ link x.obj
$ run x.exe
1? s = 0
2? s = 123456789
$
x.c
---
#include
#include
size_t s = 0;
#ifdef __cplusplus
extern "C" {
#endif
void* decc$malloc(size_t size);
void* malloc(size_t size) { s = size; return decc$malloc(size); }
#ifdef __cplusplus
}
#endif
int main() {
printf("1? s = %d\n", s);
malloc(123456789);
printf("2? s = %d\n", s);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2010 12:33 PM
тАО11-08-2010 12:33 PM
Re: Size of memory block pointed by a pointer?
Get a copy of the sources for the LIB$*VM routines, which underpin the CRTL heap management routines. As Hein has found by experiment, LIB$GET_VM keeps some information about the allocation in the quadword immediately below the allocated block. Rather than make assumptions, use the source to determine exactly what it is, and how you might use it.
Note there is are two LIBRTL "hidden" routines which are exposed in the symbol vector, LIB$$GET_VM_POINTERS and LIB$$GET_VM_POINTERS_64. (note the double $). There's a chance they're used to decode the meta data in an allocated block. As they say "Use the source Luke".