I'm having a little problem:
I was developing an aplication with 1 Byte 'Struct member alignment' (In
Project Settings | C/C++ | Code Generation | Struct member alignment) and it
was working fine.
Then I've tried to change to 8 Byte Alignment (the default) and it began to
give some problems.
Does anyone knows what can be happening?
I'm using Visual C++ 6.0 and WinNT 4.0
I've tried debugging and found that a call to 'calloc' returned NULL!
The code is:
typedef void * lps_LPVOID;
lps_LPVOID lps_Alloc(size_t n, lps_SWORD *errorCode)
{
lps_LPVOID ptr=NULL;
if( !n || ((ptr = (lps_LPVOID)calloc(n, 1)) == NULL) )
*errorCode = CDM_ERR_MEMORY;
else *errorCode = CDM_NO_ERROR;
return ptr;
}
Thank you,
Sérgio Ribeiro
Porto - Portugal
"Sérgio Ribeiro" <srib...@i2s.pt> wrote in message
news:uJde7jDbAHA.2108@tkmsftngp04...
void * __cdecl _heap_alloc_base (size_t size)
{
#ifdef WINHEAP
void * pvReturn;
#else /* WINHEAP */
_PBLKDESC pdesc;
_PBLKDESC pdesc2;
#endif /* WINHEAP */
#ifdef WINHEAP
if (size <= __sbh_threshold)
{
_mlock(_HEAP_LOCK);
pvReturn = __sbh_alloc_block(size);
_munlock(_HEAP_LOCK);
if (pvReturn)
return pvReturn;
}
if (size == 0)
size = 1;
size = (size + BYTES_PER_PARA - 1) & ~(BYTES_PER_PARA - 1);
// I can't step into this next function but it returns NULL
return HeapAlloc(_crtheap, 0, size);
}
What is the value of n? Do you have the memory available?
<<Remove the del for email>>
By default, VC++ 6 uses 8 byte alignment. This is fast and compatible with
the libraries. If u are using your old 1 byte packed structures from binary
files you should use the following lines of codes
#pragma pack (push, old_structure)
// save current alignment info
#pragma pack (1)
// declare your 1 byte aligned structures (old ones) here
#pragma pack (pop, old_structure)
// end of 1 byte alignment
U should also take care of your old libraries. I suggest you to work with 8
byte packaging for your new projects. By the way, VB is still using 1 byte
packaging. So you need to use listed codes to importing structures created
by VB. :)
I hope this helps.
"Sérgio Ribeiro" <srib...@i2s.pt> wrote in message
news:uJde7jDbAHA.2108@tkmsftngp04...
>
Sérgio Ribeiro
Porto - Portugal
Barry Schwarz <schw...@deloz.net> wrote in message
news:920cn9$hb3$2...@216.39.130.165...
> On Fri, 22 Dec 2000 17:02:37 -0000, "Sérgio Ribeiro" <srib...@i2s.pt>
> wrote:
>
<snip>
Knowing that 8 byte is the default is what is "driving me crazy" - isn't it
funny that all is well with 1 byte alignment?
I've all the sources for my application (no binary files nor DLL's what so
ever) so everything is compiled to 8 bytes.
Sérgio Ribeiro
Porto - Portugal
Erhan Toker <er...@taliasoft.com> wrote in message
news:uGayA29bAHA.1712@tkmsftngp02...
> Hi,
>
> By default, VC++ 6 uses 8 byte alignment. This is fast and compatible with
> the libraries. If u are using your old 1 byte packed structures from
binary
> files you should use the following lines of codes
>
> #pragma pack (push, old_structure)
>
> // save current alignment info
>
> #pragma pack (1)
>
> // declare your 1 byte aligned structures (old ones) here
>
> #pragma pack (pop, old_structure)
> // end of 1 byte alignment
>
> U should also take care of your old libraries. I suggest you to work with
8
> byte packaging for your new projects. By the way, VB is still using 1 byte
> packaging. So you need to use listed codes to importing structures created
> by VB. :)
>
> I hope this helps.
>
> "Sérgio Ribeiro" <srib...@i2s.pt> wrote in message
> news:uJde7jDbAHA.2108@tkmsftngp04...
> >
<snip>