forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

aligning data when allocating dynamically?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Stellar



Joined: 12 Dec 2005
Posts: 48

PostPosted: Thu Jan 12, 2006 1:02 pm    Post subject: aligning data when allocating dynamically? Reply with quote

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:

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 :)
_________________
Back to top
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jan 12, 2006 2:49 pm    Post subject: Reply with quote

Use memalign() to allocate aligned memory.
Back to top
View user's profile Send private message Visit poster's website
Stellar



Joined: 12 Dec 2005
Posts: 48

PostPosted: Thu Jan 12, 2006 11:36 pm    Post subject: Reply with quote

thanks ooPo :)
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group