Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Highlighted
paolo_venturi Absent Member.
Absent Member.
988 views

Memory allocation/free with C/Cobol

Hello,

i'm trying to write a C dll that called in a Cobol program returns data in a memory section allocated with C malloc().

The problem is when i'm trying to free that memory in Cobol with a m$free it seems doesn't work.

My question is: m$free work only with memory allocated with m$alloc?

There is a way to free in Cobol a memory section allocated with C malloc()?

There is a way to allocate in C a memory section using the Cobol m$alloc?

0 Likes
4 Replies
mhanson Absent Member.
Absent Member.

RE: Memory allocation/free with C/Cobol

m$malloc and m$free aren't direct interfaces to the system malloc() and free() routines so you can't mix and match them. You should be able to add your own call to free() using the sub or sub85 interfaces. See lib/sub.c and lib/sub85.c.
0 Likes
paolo_venturi Absent Member.
Absent Member.

RE: Memory allocation/free with C/Cobol

Hi.

We are looking for a way to allocate "cobol memory" from C.  This should allow us to free that memory simply using m$free.

We got the "rtcallbk.h" header file, the structure RUNTIME_CALLS_TABLE and its function pAmalloc.

It seems to be what we are lookin for but .... we cannot find the library that define that structure so we get a linking error: 

                     LNK1120 1 unresolved externals

 

Someone can help us ?

Thank you

0 Likes
dalekreitzer
Visitor.

RE: Memory allocation/free with C/Cobol

If you have access to the DLL, the quickest and easiest way would (probably) be to simply write your own method to clear it within the C shell. You created it there, why not clear it from there as well?

Dale

0 Likes
paolo_venturi Absent Member.
Absent Member.

RE: Memory allocation/free with C/Cobol

Because we want to create our standard structure in C in an allocated memory and free that memory in Cobol without worrying about who has allocated this memory.

Paolo
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.