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 8188557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:57:17+00:00 2026-06-07T02:57:17+00:00

I’m fairly new to the D2 programming language. I need to implement a quad

  • 0

I’m fairly new to the D2 programming language. I need to implement a quad edge data structure. This is an adjacency data structure for effective graph embeddings and their duals.
From previous experience with C, I started with the following implementation:

struct edge(T) {
    edge* next;
    T* data;
    uint position;
}
alias edge[4] qedge;
edge* new_edge() {
    qedge* q = new qedge; // does not compile, just analogous
    // initialize the four edges (q[i].position = i)
    return cast (edge*) q;
}

That works fine, but this position field is bugging me – it is just wasting space there.
Is there a way to align to a (8 * ${machine word size}) boundary when allocating the memory for the qedge array (then I will not need the additional position field, because the information at which position an edge is in the qedge array will be encoded into the edge address)?

I’m aiming at an efficient and cute implementation (that’s why I’ve chosen D), so any other suggestions are welcome.

EDIT: Here is a piece of code to make the thing more clear http://dpaste.dzfl.pl/e26baaad:

module qedge;

class edge(T) {
    edge next;
    T* data;
}

alias edge!int iedge;
alias iedge[4] qedge;

import std.stdio;
import std.c.stdlib;

void main() {
    writeln(iedge.sizeof); // 8
    writeln(qedge.sizeof); // 32
    // need something for the next line, 
    // which always returns an address, divisible by 32
    qedge* q = cast (qedge*) malloc(qedge.sizeof);
    writeln(q); // ex. 0x10429A0 = 17050016, which is, does not start at 32-byte boundary
}
  • 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-06-07T02:57:19+00:00Added an answer on June 7, 2026 at 2:57 am

    To directly answer the question – use the align(N) to specify the alignment you want. However, keep this in mind (quote from dlang.org): Do not align references or pointers that were allocated using NewExpression on boundaries that are not a multiple of size_t

    Reference manual at http://dlang.org has a section about alignment – http://dlang.org/attribute.html#align .

    Say, the T is int – the edge!int is already 24 bytes big on 64-bit architecture.
    D is not so different from C in alignment. Check the following (runnable/editable code at: http://dpaste.dzfl.pl/de0121e1):

    module so_0001;
    // http://stackoverflow.com/questions/11383240/custom-alignment-options-for-an-efficient-quad-edge-implementation
    
    struct edge(T) {
        edge* next;
        T* data;
        uint position;
    }
    alias edge!int iedge;
    alias edge!int[4] qedge;
    
    /* not a good idea for struct... it is a value type...
    edge!int new_edge() {
        // in the original example it used new... D is not C++ to mix value and reference types! :)
    }
    */
    
    import std.stdio;
    
    int main() {
        writeln(iedge.sizeof);
    
        //                                   64bit
        //                                ----------
        writeln(iedge.next.offsetof);     // 0
        writeln(iedge.data.offsetof);     // 8
        writeln(iedge.position.offsetof); // 16
        writeln(qedge.sizeof);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.