[erlang-questions] Cross-referencing binaries

Roger Lipscombe roger@REDACTED
Mon Dec 18 15:35:09 CET 2017


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.



More information about the erlang-questions mailing list