aligning data when allocating dynamically?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Stellar
Posts: 48
Joined: Mon Dec 12, 2005 9:13 am

aligning data when allocating dynamically?

Post by Stellar »

the samples show how to align data when allocating data statically

ie..

static unsigned int __attribute__((aligned(16))) list[262144];

but what if you want to do it dynamically?

given the below, how could i modify the line to be 16 byte aligned?

MESH *pMesh;

... allocate mesh ...

pMesh->pVerticies = ( VTX ) calloc( sizeof( VTX ) , nVerticies );


______ structure definitions below_____________

Code: Select all

typedef struct XlVertex
{
	float u, v;
	float x, y, z;
} *VTX; // 5 floats * 4 bytes = 20 bytes per vertex

typedef struct MeshNode
{
	int nTriangles;
	int nVerticies;
	int nIndicies;
	int nMeshId;

	char szMeshName[256];

	vtx pVerticies;
	unsigned short *pIndicies;

	MeshNode*pNext;
} *MESH;
thanks :)
Image
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Use memalign() to allocate aligned memory.
User avatar
Stellar
Posts: 48
Joined: Mon Dec 12, 2005 9:13 am

Post by Stellar »

thanks ooPo :)
Image
Post Reply