Highlighted
New Member.
1925 views

M$ALLOC vs BY REFERENCE

Can someone explain to me what the difference between these 2 bits of code are?  I thought they would essentially do the same thing... I don't understand why when I call some dll's either works fine. And other dll's only work using the M$ALLOC method. There must be something different about these that I don't understand OR maybe I'm completely off my rocker here and have no idea whatsoever 🙂 

 Assume you have some dll with the function "SetData"

CALL "M$ALLOC" USING 20, PTR.
CALL "M$PUT" USING PTR, "Hello World".
IF IS-REMOTE 
    CALL "@[DISPLAY]:SetData" USING 20, BY VALUE PTR.
ELSE
    CALL "SetData" USING 20, BY VALUE PTR
END-IF.
CALL "M$FREE" USING PTR.


IF IS-REMOTE
   CALL "@[DISPLAY]:SetData" USING 20, BY REFERENCE "Hello World".
ELSE
   CALL "SetData" USING 20, BY REFERENCE "Hello World"
END-IF.

Of course I woud much rather use the code without M$ALLOC as I cannot get it to work in a thin client to unix environment.  the memory is allocated on the server and doesn't not properly pass thru to the @[DISPLAY]:SetData...

 

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: M$ALLOC vs BY REFERENCE

I believe this forum discussion may help: community.microfocus.com/.../3807.aspx

0 Likes
Highlighted
New Member.

RE: M$ALLOC vs BY REFERENCE

Thanks, I read that discusson before and it didn't really help me understand what was going on when something is passed BY REFERENCE versus using M$ALLOC and passing the actual pointer BY VALUE.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: M$ALLOC vs BY REFERENCE

In essence, there is no difference between these two approaches. In each case, you are passing an address that points to "Hello World" to the function SetData().

However, when passing addresses to the thin client, the ACUCOBOL-GT runtime detects that the memory was allocated dynamically with M$ALLOC, and in that case will pass the actual data, letting the thin client pass a pointer into the actual called function. That is why the first method works for you, and the second doesn't.

0 Likes
Highlighted
New Member.

RE: M$ALLOC vs BY REFERENCE

Thanks rzack,

Are you saying that M$ALLOC should work in a thin client environment?  I am finding that it does not work as it seems like it allocates the memory on the Unix server then when I make the @[DISPLAY]: call to the dll on the client, the address contains garbage and the dll call fails. I can only assume it's becasue the data at the address from the M$ALLOC command is located on the client and M$ALLOC stored the data at the address on the server... That all being said, if M$ALLOC could be called with the @[DISPLAY]:M$ALLOC then I would think it would all hold together... Maybe I'm crazy tho 🙂

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.