Re: byte alignment/dynamic memory from heap x64

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Tim,

Thanks for the help. I had seen the definition in the WDK header that uses
declspec(align(16)) and I was compiling with x64 compiler.

I had read on msdn that declspec(align(n)) did not work for dynamic
allocation from the heap. At any rate, all is working when I am using
ExAllocatePoolWithTag and casting to my pointer.

thanks,
Mike



"Tim Roberts" wrote:

Mike L <MikeL@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

My IM driver uses SLIST_ENTRY and SLIST_HEADER(s) and they are declared in a
struct and when my driver is loaded I dynamically allocate memory using these
structs.

for example(not my real struct...)

struct X {

int y;
PNDIS_BUFFER pBuf;
....
SLIST_HEADER ListHeader;
SLIST_ENTRY ListEntry;
...
};

The documention for x64 states that SLIST_ENTRY and SLIST_HEADER must be 16
byte aligned.

How do I force this to happen ?

You don't have to. A few minutes browsing through the include files will
show that SLIST_HEADER and SLIST_ENTRY are already declared with 16-byte
alignment. As long as your structure starts on a 16-byte boundary, the
header and entry structures will be so aligned.

Any advice is appreciated, I might have a bug in my code for one of the
above methods, so I really just need someone to tell me how this is normally
done and I can figure out the details. I saw another function
_align_memory, but did not want to link an NDIS driver to the c runtime for
memory management, but maybe that is another alternative.

You're sure you are compiling for x64? In the 32-bit build environments,
they aren't 16-byte aligned because they don't need to be.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.

.



Relevant Pages

  • Re: To C or not to C ... now what the hell to I do?
    ... Function mktime() Fix ... short version of struct tm when making a call to mktime ... This resulted in a longer struct tm. ... So clearly compiling under v8.3 gives you a couple more structure ...
    (comp.os.vms)
  • Re: invalid conversion from `int* to `socklen_t*
    ... > I am getting this error while compiling: ... there's no reason for all those "struct" specifiers ... The struct specifier is only needed for the original declaration of ... So wherever you have "struct sockaddr", ...
    (comp.lang.cpp)
  • Re: VC2008 Bug: optimising static_cast to a virtual base gives C1001 internal compile error
    ... struct A: virtual B; ... it ICEs while _compiling_, not after the linker is done with it. ... I was able to repro it on 2008 Team Edition. ... If this is an issue in real code, adding #pragma optimizebefore ...
    (microsoft.public.vc.language)
  • Re: Array.Sort a struct
    ... That's like having 5 or 7 reference type parameters. ... When it comes to sorting the array, that's going to be slower than ... The performance may shift drastically using x64, ... it still looks like a struct could be used. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Function templates
    ... > You can also restrict T for the purpose of guiding overload resolution ... no instance of function template "SQ" matches the ... template struct can_multiply ...
    (comp.lang.cpp)