Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help on Alignment

0 views
Skip to first unread message

Sérgio Ribeiro

unread,
Dec 22, 2000, 12:02:37 PM12/22/00
to

Hi there,

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


Tom Groszko

unread,
Dec 22, 2000, 12:06:51 PM12/22/00
to
Did you rebuild everything so it is all working with the same alignment?


"Sérgio Ribeiro" <srib...@i2s.pt> wrote in message
news:uJde7jDbAHA.2108@tkmsftngp04...

Sérgio Ribeiro

unread,
Dec 22, 2000, 12:19:13 PM12/22/00
to

Yes.


Tom Groszko <gros...@rapistan.com> wrote in message
news:eWuIlmDbAHA.2072@tkmsftngp05...

Sérgio Ribeiro

unread,
Dec 22, 2000, 12:57:25 PM12/22/00
to

Steping into 'calloc' function I reach "__cdecl _heap_alloc_base" and it
looks like this: (see my comment in code)


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);
}

Barry Schwarz

unread,
Dec 22, 2000, 3:14:33 PM12/22/00
to
On Fri, 22 Dec 2000 17:02:37 -0000, "Sérgio Ribeiro" <srib...@i2s.pt>
wrote:

What is the value of n? Do you have the memory available?


<<Remove the del for email>>

Erhan Toker

unread,
Dec 26, 2000, 5:05:39 AM12/26/00
to
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...
>

Sérgio Ribeiro

unread,
Dec 27, 2000, 5:32:50 AM12/27/00
to

n has the value 16000 (less than 16KB) and I've 128 MB (when I run my
application Task Manager says I'm using 105 MB, so I don't think that this
is a problem).

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>

Sérgio Ribeiro

unread,
Dec 27, 2000, 6:23:06 AM12/27/00
to

Hi Erhan,

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>


0 new messages