Cross-referencing binaries

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cross-referencing binaries

Roger Lipscombe-2
If I get the list of binaries for a process, using process_info(Pid,
binary), each returned binary has an Id. If I find the same Id in the
list of binaries for another process, is it the same binary?

Or, in other words, can I do something like the following...

D = lists:foldl(
    fun(Pid, A) ->
        try
            {binary, Bins} = erlang:process_info(Pid, binary),
            lists:foldl(
                fun({Ref, Size, Count}, B) ->
                    dict:update(Ref, fun({X, L}) -> {X + 1, [Pid | L]}
end, {1, [Pid]}, B)
                end, A, Bins)
        catch
            _:_ ->
                A
        end
    end, dict:new(), erlang:processes()).

...to build a dictionary from binary Id to owner(s)?

It appears to work; I'm just not sure it's correct.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Cross-referencing binaries

Lukas Larsson-8
Hello,

On Mon, Dec 18, 2017 at 3:35 PM, Roger Lipscombe <[hidden email]> wrote:
If I get the list of binaries for a process, using process_info(Pid,
binary), each returned binary has an Id. If I find the same Id in the
list of binaries for another process, is it the same binary?

yes, it is the same binary. The ID is, in the current implementation, the pointer to the binary data.

Lukas

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions