Dynamic Allocation of User-Defined Structure Type
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Dynamic Allocation of User-Defined Structure Type

Threaded View

  1. #1
    Join Date
    Mar 2010
    Posts
    11

    Exclamation Dynamic Allocation of User-Defined Structure Type

    Hi everyone

    I'm working on a video processing project using Visual Studios 2008 (on a Vista OS), and I've been timing each function in order to see where my code is running the slowest.

    I've isolated it down to when I allocated memory dynamically using malloc for two structures which I have made respective typedefs for. The majority of the computation time is purely due to allocating memory to these two structures. I'm fairly new to C, so I'm probably overlooking some vital fact regarding efficient memory allocation.

    Here is the code snippet for when memory is allocated:

    *********************************************************************
    RegularStructure *reg;
    VirtualStructure *vir;

    reg = ( RegularStructure* ) malloc( imHeight*imWidth * sizeof( RegularStructure ) );
    vir = ( VirtualStructure* ) malloc( imHeight*imWidth * sizeof( VirtualStructure ) );
    *********************************************************************



    The type definitions are part of a header file, here is the relevant code:



    Code:
    *********************************************************************
    typedef struct RegularStructure
    {
    
    	int type;
    	float hue;
    	float saturation;
    	float value;
    	int sonType;
    	int regSonCount;
    	int virSonCount;
    	int regSonsRow[ 2000 ];
    	int regSonsCol[ 2000 ];
    	int virSonsRow[ 2000 ];
    	int virSonsCol[ 2000 ];
    	int parentType;
    	int regParentRow;
    	int regParentCol;
    	int virParentRow;
    	int virParentCol;
    	int regIntraCount;
    	int regIntraRow[ 300 ];
    	int regIntraCol[ 300 ];
    	int virIntraCount;
    	int virIntraRow[ 300 ];
    	int virIntraCol[ 300 ];
    
    } RegularStructure;
    
    typedef struct VirtualStructure
    {
    
    	int type;
    	float hue;
    	float saturation;
    	float value;
    	int sonType;
    	int regSonCount;
    	int virSonCount;
    	int regSonsRow[ 2000 ];
    	int regSonsCol[ 2000 ];
    	int virSonsRow[ 2000 ];
    	int virSonsCol[ 2000 ];
    	int parentType;
    	int regParentRow;
    	int regParentCol;
    	int virParentRow;
    	int virParentCol;
    	int regIntraCount;
    	int regIntraRow[ 300 ];
    	int regIntraCol[ 300 ];
    	int virIntraCount;
    	int virIntraRow[ 300 ];
    	int virIntraCol[ 300 ];
    
    } VirtualStructure;
    *******************************************************************

    If anyone can provide help or insight, it would be greatly appreciated.

    Faithfully,
    John.
    Last edited by Marc G; March 11th, 2010 at 09:58 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center