Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why don't 1-byte data types call cdr_alignment for byte alignment? #360

Open
Jackie2chen opened this issue Jun 21, 2024 · 2 comments
Open

Comments

@Jackie2chen
Copy link

Byte Alignment Rule and Zero-Copy Support

Due to this byte alignment rule, case 2 does not support zero-copy, but case 1 does.

Byte Alignment Code

switch (getKind()) {
    case com.eprosima.idl.parser.typecode.Kind.KIND_LONG:
    case com.eprosima.idl.parser.typecode.Kind.KIND_ULONG:
    case com.eprosima.idl.parser.typecode.Kind.KIND_FLOAT:
        current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4);
        break;
    case com.eprosima.idl.parser.typecode.Kind.KIND_SHORT:
    case com.eprosima.idl.parser.typecode.Kind.KIND_USHORT:
        current_alignment += 2 + TypeCode.cdr_alignment(current_alignment, 2);
        break;
    case com.eprosima.idl.parser.typecode.Kind.KIND_BOOLEAN:
    case com.eprosima.idl.parser.typecode.Kind.KIND_CHAR:
    case com.eprosima.idl.parser.typecode.Kind.KIND_OCTET:
    case com.eprosima.idl.parser.typecode.Kind.KIND_INT8:
    case com.eprosima.idl.parser.typecode.Kind.KIND_UINT8:
        current_alignment += 1;
        break;
}

Case 1: Supports Zero-Copy

module DDS {
#define MAX_SIZE (1920 * 1200 * 3)
    struct Header {
        unsigned long long eightbytes0;
        long fourbytes1;
        long fourbytes2;
        long fourbytes3;
        char onebyte1;
    };
    struct LoanableHelloWorld {
        long fourbytes1;
        long fourbytes2;
        long fourbytes3;
        Header header;
        unsigned long fourbytes4;
        unsigned long fourbytes5;
        long fourbytes6;
    };
};

Case 1 Screenshot

Case 2: Does Not Support Zero-Copy

module DDS {
#define MAX_SIZE (1920 * 1200 * 3)
    struct Header {
        unsigned long long eightbytes0;
        long fourbytes1;
        long fourbytes2;
        long fourbytes3;
        char onebyte;
    };
    struct LoanableHelloWorld {
        long fourbytes1;
        long fourbytes2;
        long fourbytes3;
        Header header;
        char onebyte;
        unsigned long fourbytes4;
        unsigned long fourbytes5;
        long fourbytes6;
    };
};

屏幕截图 2024-06-21 161430

is that a bug?

@MiguelCompany
Copy link
Member

@Jackie2chen Nested structures don't usually play well with Zero-Copy. See #193 for a nice discussion on this

@Jackie2chen
Copy link
Author

Thank you for your reply. But why is it necessary to consider the CDR specification when using zero-copy? What is the significance of this operation? Is it because OMG requires it to be implemented this way?

Is it possible to determine whether a struct in the IDL supports zero-copy through a script or other means without compiling the generated code?

I look forward to your professional response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants