[cgma-dev] cgm-cubit on 32 bit machine
Iulian Grindeanu
iulian at mcs.anl.gov
Fri Jul 1 12:34:41 CDT 2011
OK,
it is 124 from sizeof, compared to 136 from your code snippet.
So buff[12] would do it.
This crash appears only on 32 bit.
Running this on 64 bit machine it shows that we are lucky it doesn't crash
on 64 bit, because :
CCubitFile constructor touched 208 bytes
sizeof (NCubitFile::CCubitFile): 192
Probably we would want to add some buffer for 64 bit too.
Thanks,
Iulian
----- Original Message -----
> On 07/01/2011 11:44 AM, Iulian Grindeanu wrote:
> >
>
> >
> > Thanks Jason,
> > So when I add at the end of CubitFile.hpp
> >
> > Index: CubitFile.hpp
> > ===================================================================
> > --- CubitFile.hpp (revision 5042)
> > +++ CubitFile.hpp (working copy)
> > @@ -291,6 +291,7 @@
> > UnsignedInt32 mintNumModels;
> > SModelData* mpaModelData;
> > } mModelBuff;
> > + char buff[12];
> > };
> >
> > } // namespace NCubitFile
> >
> > it compiles and runs "fine". If I do only char[4], it crashes early,
> > and when I do
> > char[8], it crashes more spectacularly, with a stack corruption.
> >
>
> OK. If you want to determine the exact size, you try something like
> this:
>
> const char some_byte = 0xEE;
> char some_mem[4096];
> memset( some_mem, some_byte, sizeof(some_mem) );
> CCubitFile* ptr = new (some_mem) CCubitFile;
> size_t last_changed = 0;
> for (size_t i = 0; i < sizeof(some_mem); ++i)
> if (some_mem[i] != some_byte)
> last_changed = i;
> printf("CCubitFile constructor touched %lu bytes\n", (unsigned
> long)last_changed+1);
>
> But knowing the exact size probably isn't that important.
>
>
> - jason
More information about the cgma-dev
mailing list