Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6701315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:55:10+00:00 2026-05-26T06:55:10+00:00

Disclaimer: The author of this post is a C++ beginner. In my Erlang code,

  • 0

Disclaimer: The author of this post is a C++ beginner.

In my Erlang code, I have a data structure which represents a directed graph:

-record(vertex_entry, {vertex_name, outgoing_edges}).
-record(outgoing_edge, {edge_weight, neighbour_name}).

Edge1 = #outgoing_edge{edge_weight = 12.5, neighbour_name = 2},
Edge2 = #outgoing_edge{edge_weight = 11.2, neighbour_name = 3},

Edges = [Edge1,Edge2],

Vertex1 = #vertex_entry{vertex_name = 1, outgoing_edges = Edges},
Vertex4 = #vertex_entry{vertex_name = 4, outgoing_edges = Edges},

Graph = [Vertex1,Vertex4].

I would like to pass this graph to C++ through the Erlang’s port functionality.

On the C++ side I would like to convert this Erlang graph to a graph of the following structure (it is a CUDA-optimized adjacency list structure):

typedef struct
{
// (V) This contains a pointer to the edge list for each vertex
int *vertexArray;
// Vertex count
int vertexCount;
// (E) This contains pointers to the vertices that each edge
// is attached to
int *edgeArray;
// Edge count
int edgeCount;
// (W) Weight array
float *weightArray;
} GraphData;

Perhaps, the C++ graph generation code from the same source (Chapter 16 of the book) would be helpful to solve the issue:

void generateRandomGraph(GraphData *graph, int numVertices, int neighborsPerVertex)
{
    graph->vertexCount = numVertices;
    graph->vertexArray = (int*) malloc(graph->vertexCount * sizeof(int));
    graph->edgeCount = numVertices * neighborsPerVertex;
    graph->edgeArray = (int*)malloc(graph->edgeCount * sizeof(int));
    graph->weightArray = (float*)malloc(graph->edgeCount * sizeof(float));

    for(int i = 0; i < graph->vertexCount; i++)
    {
        graph->vertexArray[i] = i * neighborsPerVertex;
    }

    for(int i = 0; i < graph->edgeCount; i++)
    {
        graph->edgeArray[i] = (rand() % graph->vertexCount);
        graph->weightArray[i] = (float)(rand() % 1000) / 1000.0f;
    }
}

I assume that the Erlang’s ports functionality will help me to pass the data from Erlang to C++ in a binary format.

So, the question is:
How do I recover and convert a certain Erlang data structure (which represents a graph) into the aforementioned user-specified C++ graph data structure in C++ code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:55:11+00:00Added an answer on May 26, 2026 at 6:55 am

    Unless performance is critical here, consider serialising to text instead, in a format which is easy to parse. It’ll save you lots of debugging effort if you can read the output, save it to file when testing the read side, etc.

    Even if you do decide to switch to a binary encoding, writing out the text encoding first might help decide the layout. My response to your other question should give you a pointer on the basics of reading binary, instead of text input, on the C++ side.

    Also, if you’re relatively new to C++, you might as well start out with good idiomatic style if possible: consider replacing your int* arrays and manual allocations with std::vector<int>, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

( Disclaimer: This question is not specific to ASP.NET) I have a control which
Disclaimer: The author is a newbie in OTP having some basic knowledge of Erlang's
Disclaimer: the author is at the beginner level in C/C++. Wikipedia says that OpenCL
Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: I'm stuck on TFS and I hate it. My source control structure looks
Disclaimer: This is for a homework assignment, but the question is not regarding the
DISCLAIMER: The following code is not something I would ever use in a real
Disclaimer This is not strictly a programming question, but most programmers soon or later
Disclaimer: I realize I can generate this at runtime in Java, this was needed
Disclaimer: I have no experience using YUI at all. I was wondering how the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.