From: Bryon Daly <[EMAIL PROTECTED]>

On 2/9/06, The Fool <[EMAIL PROTECTED]> wrote:
>Ok so this is what I've been doing:

I'll cut down to the meat of it:

>   *((int *) &Mem[PutAt * __Int_Size__])       = PutMe;

This looks reasonable.  I presume that Mem[] is a char or byte array of some
kind...  Are you only writing ints into Mem[]?  If you're going to mix data
types in the same buffer, you'll need to consider data packing or padding,
and possibly be aware of data alignment issues.

-------

The Data I'm Copying from isn't exactly contigous:

In fact this is how I access it:

#define MappingBytes(x, y, z, w, q) MappingBytes+((z*(q+1)*(w+1))+(y*(w+1))+x)

Or Actually

#define PDataAt(x,y)     
(*(mappping.MapppingBytes((x),(y),1,Test1.head->X,Test1.head->Y)))

Which is basically:

// Binomial expansion for a VB  array =                      a
// Binomial expansion for a VB  array =             (b*a1) + a
// Binomial expansion for a VB  array = (c*b1*a1) + (b*a1) + a

Which is quite differenet from:

// Binomial expansion for a C++ array =  a
// Binomial expansion for a C++ array = (a*b1)    +  b
// Binomial expansion for a C++ array = (a*b1*c1) + (b*c1) + c

---
Anyway this is the class so far:

// MemClass.h -- Memory Class Definition

#ifndef _MEMCLASS_H_
        #define _MEMCLASS_H_
        #ifndef  WIN32_LEAN_AND_MEAN
        #define  WIN32_LEAN_AND_MEAN
        #endif
        
        typedef struct _FlipBytes
                       {
                       BYTE      One;
                       BYTE      Two;
                       BYTE      Tre;
                       BYTE      For;
                       } FlipBytes;
        
        typedef union  _FlipInt
                       {
                       int       Flip;
                       FlipBytes Flop;
                       } FlipInt;
        
        #define  __HiMemBlock__     1023
        #define  __LoMemBlock__      255
        #define  __BYTE_Size__         1
        #define  __Short_Size__        2
        #define  __Int_Size__          4
        #define  __Long_Size__         4
        #define  __Int64_Size__        8
        
        #include "basetsd.h"
        #include <windows.h>
        #include "X-Macros.h"
        
        extern   HWND hiwind;
        
        class IMem
              {
              private: //
                       
                       BYTE  *Mem;                   // pointer to Mem
                       long  MemSize;                // Size in Bytes of Mem
                       long  CurrentSize;            // Size in Bytes of Mem
                       
                       int  *temp;                   // pointer to temp  Mem
                       int   MeLen;                  // Temp size of new Mem
                       int   i;                      // Temp
                       
              public:  //
                       
                       IMem(const long AllocBytes);  // default constructor
                       IMem(const IMem &s);          // Copy    constructor
                       
                       ReAlloc (const long AllocBytes);
                       
                       char    *GetChar()     const { return (char    *) Mem; }
                       BYTE    *GetByte()     const { return (BYTE    *) Mem; }
                       INTS    *GetInts()     const { return (INTS    *) Mem; }
                       UINTS   *GetUInts()    const { return (UINTS   *) Mem; }
                       int     *GetInt()      const { return (int     *) Mem; }
                       UINT    *GetUInt()     const { return (UINT    *) Mem; }
                       long    *GetLong()     const { return (long    *) Mem; }
                       ULONG   *GetULong()    const { return (ULONG   *) Mem; }
                       __int64 *GetInt64()    const { return (__int64 *) Mem; }
                       UINT64  *GetUInt64()   const { return (UINT64  *) Mem; }
                       
                       int PutChar(const   long PutAt, const char    PutMe);
                       int PutByte(const   long PutAt, const BYTE    PutMe);
                       int PutInts(const   long PutAt, const INTS    PutMe);
                       int PutUInts(const  long PutAt, const UINTS   PutMe);
                       int PutInt(const    long PutAt, const int     PutMe);
                       int PutUInt(const   long PutAt, const UINT    PutMe);
                       int PutLong(const   long PutAt, const long    PutMe);
                       int PutULong(const  long PutAt, const ULONG   PutMe);
                       int PutInt64(const  long PutAt, const __int64 PutMe);
                       int PutUInt64(const long PutAt, const UINT64  PutMe);
                       
                       long GetSize()         const { return CurrentSize; }
                       long GetRealSize()     const { return MemSize; }
                       
                       void TestPut();
                       void TestPut2();
                       
                       //copy data from pointer fuction
                       
                       ~IMem();                      // destructor
              };
#endif


// MemClass.cpp

#ifndef  WIN32_LEAN_AND_MEAN
#define  WIN32_LEAN_AND_MEAN
#endif

#include <stdlib.h>
#include "basetsd.h"
#include <windows.h>

#include "MemClass.h"

#include "X-Macros.h"
#include "temp.h"

// Constructors

IMem::IMem(const long AllocBytes)    // default constructor
     {
     CurrentSize            = 0;
     MemSize                = 0;
     Mem                    = NULL;
     temp                   = NULL;
     
     try //
         {
         if (AllocBytes <= __LoMemBlock__)
            {
            MemSize         = __LoMemBlock__;
            }
         else // >__LoMemBlock__
              {
              i             = (AllocBytes / __HiMemBlock__) + 1;
              MemSize       = i * __HiMemBlock__;
              
              while (MemSize < AllocBytes)
                    {
                    i++;
                    MemSize = i * __HiMemBlock__;
                    }
              }
         CurrentSize        = AllocBytes;
         Mem                = new BYTE[MemSize];
         }
     catch (...)
           {
           delete [] Mem;
           Mem              = NULL;
           CurrentSize      = 0;
           MemSize          = 0;
           Enterprise();
           MessageBox(hiwind,"IMem Constructor Threw an Exception","REALLY 
bad",MB_OK);
           // Call Panic Save HERE
           Excelsior();
           throw;
           }
     }

IMem::IMem(const IMem &s)      // Copy    constructor
     {
     CurrentSize            = 0;
     MemSize                = 0;
     Mem                    = NULL;
     temp                   = NULL;
     
     try //
         {
         MemSize            = s.MemSize;
         CurrentSize        = s.CurrentSize;
         Mem                = new BYTE[MemSize];
         
         for (i = 0; i < CurrentSize; i++)
             {
             *(&Mem[i])     = (s.Mem)[i];
             }
         }
     catch (...)
           {
           delete [] Mem;
           Mem              = NULL;
           CurrentSize      = 0;
           MemSize          = 0;
           Enterprise();
           MessageBox(hiwind,"IMem Copy Constructor Threw an Exception","REALLY 
bad",MB_OK);
           // Call Panic Save HERE
           Excelsior();
           }
     }

// Deconstructor

IMem::~IMem()
     {
     delete [] Mem;
     Mem             = NULL;
     }

// IMem Functions

IMem::ReAlloc (const long AllocBytes)
     {
     if (AllocBytes > MemSize)
        {
        try //
            {
            if (AllocBytes <= __LoMemBlock__)
               {
               MemSize         = __LoMemBlock__;
               }
            else // >__LoMemBlock__
                 {
                 i             = (AllocBytes / __HiMemBlock__) + 1;
                 MemSize       = i * __HiMemBlock__;
                 
                 while (MemSize < AllocBytes)
                       {
                       i++;
                       MemSize = i * __HiMemBlock__;
                       }
                 }
            CurrentSize        = AllocBytes;
            Mem                = new BYTE[MemSize];
            }
        catch (...)
              {
              delete [] Mem;
              Mem              = NULL;
              CurrentSize      = 0;
              MemSize          = 0;
              Enterprise();
              MessageBox(hiwind,"IMem Constructor Threw an Exception","REALLY 
bad",MB_OK);
              // Call Panic Save HERE
              Excelsior();
              throw;
              }
        }
     else //
          {
          CurrentSize = AllocBytes;
          }
     }

int IMem::PutChar(const   long PutAt, const char         PutMe)
    {
    if (PutAt <= CurrentSize)
       {
       try //
           {
           *((char     *) &Mem[PutAt])                 = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutChar Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutByte(const   long PutAt, const BYTE         PutMe)
    {
    if (PutAt <= CurrentSize)
       {
       try //
           {
           *(&Mem[PutAt])                              = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutBYTE Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutInts(const   long PutAt, const INTS         PutMe)
    {
    if ((PutAt * __Short_Size__) <= CurrentSize)
       {
       try //
           {
           *((INTS *) &Mem[PutAt * __Short_Size__])    = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutINTS Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutUInts(const  long PutAt, const UINTS        PutMe)
    {
    if ((PutAt * __Short_Size__) <= CurrentSize)
       {
       try //
           {
           *((UINTS *) &Mem[PutAt * __Short_Size__])   = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutUINTS Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutInt(const    long PutAt, const int          PutMe)
    {
    if ((PutAt * __Int_Size__) <= CurrentSize)
       {
       FlipInt Me;
               Me.Flip = PutMe;
       XorSwap(Me.Flop.For,Me.Flop.One);
       XorSwap(Me.Flop.Tre,Me.Flop.Two);
       int PutNewMe = Me.Flip;
       try //
           {
           *((int *) &Mem[PutAt * __Int_Size__])       = PutNewMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutInt Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutUInt(const   long PutAt, const UINT         PutMe)
    {
    if ((PutAt * __Int_Size__) <= CurrentSize)
       {
       try //
           {
           *((UINT *) &Mem[PutAt * __Int_Size__])      = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutUINT Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutLong(const   long PutAt, const long         PutMe)
    {
    if ((PutAt * __Long_Size__) <= CurrentSize)
       {
       try //
           {
           *((long *) &Mem[PutAt * __Long_Size__])     = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutLong Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutULong(const  long PutAt, const ULONG        PutMe)
    {
    if ((PutAt * __Long_Size__) <= CurrentSize)
       {
       try //
           {
           *((ULONG *) &Mem[PutAt * __Long_Size__])    = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutULONG Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutInt64(const  long PutAt, const __int64      PutMe)
    {
    if ((PutAt * __Int64_Size__) <= CurrentSize)
       {
       try //
           {
           *((__int64 *) &Mem[PutAt * __Int64_Size__]) = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutInt64 Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

int IMem::PutUInt64(const long PutAt, const UINT64       PutMe)
    {
    if ((PutAt * __Int64_Size__) <= CurrentSize)
       {
       try //
           {
           *((UINT64 *) &Mem[PutAt * __Int64_Size__])  = PutMe;
           }
       catch (...)
             {
             Enterprise();
             MessageBox(hiwind,"IMem PutUINT64 Threw an Exception","REALLY 
bad",MB_OK);
             // Call Panic Save HERE
             Excelsior();
             return No;
             }
       
       return Yes;
       }
    else //
         {
         return No;
         }
    }

void IMem::TestPut()
     {
     if (CurrentSize >20)
        {
        Mem[0] = 167;
         Mem[1]=17;
         Mem[2]=94;
         Mem[3]=77;
         Mem[4]=18;
         Mem[5] =55;
         Mem[6] = 255;
         Mem[7]=0;
         Mem[8]=88;
        }
     }

void IMem::TestPut2()
     {
     if (CurrentSize >40)
        {
        PutInt(0,32567);
        PutInt(1,32);
        PutInt(2,567);
        PutInt(3,256);
        PutInt(4,25);
        PutInt(5,67);
        PutInt(6,132567);
        PutInt(7,8765);
        PutInt(8,985);
        }
     }

_______________________________________________
http://www.mccmedia.com/mailman/listinfo/brin-l

Reply via email to