DEVICE_EXTENSION + Classes

Hi there, one of my DEVICE_EXTENSION parameters is an object of some class.
When the system initializes the device_extension calls the constractor
of the class as well?
I think not.

It depends on how the object is defined. There is no runtime support for
C++ in the kernel, so you have to provide your own global new and delete
operators. As there is no runtime support, and as your device extension
is allocated as a blob of memory, not an object, you have to perform
your own initialization. The typical approach to this problem is to use
the ‘placement new’ form of the new operator to invoke the constructor
over a pre-allocated chunk of memory.

You can have each class define its own class new and delete and avoid
the global issue. You can download an ancient but usable c++ runtime
from my website (www.hollistech.com) and there are other freely
available kernel runtimes.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolas
Stylianides
Sent: Tuesday, July 26, 2005 9:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] DEVICE_EXTENSION + Classes

Hi there, one of my DEVICE_EXTENSION parameters is an object of some
class.
When the system initializes the device_extension calls the constractor
of the class as well?
I think not.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

And of course you did define the constructor of the class you are using in
your device extension? You’re compiling the source file as a CPP source
file? Are you rolling your own classes or using DriverWorks?


The personal opinion of
Gary G. Little

“Nikolas Stylianides” wrote in message news:xxxxx@ntdev…
> Hi there, one of my DEVICE_EXTENSION parameters is an object of some
> class.
> When the system initializes the device_extension calls the constractor of
> the class as well?
> I think not.
>
>
>
>

Gary G. Little wrote:

And of course you did define the constructor of the class you are using in
your device extension? You’re compiling the source file as a CPP source
file? Are you rolling your own classes or using DriverWorks?

my classes declarations are in *.cpp files.
Nevertheless when Device extension is created there is no way to call
the constractor. So i will use
functions like “Init” and “Terminate”. For heap creations, Mark is
right, i have to declare each class with operator new and delete.
Thank you very much.

You can invoke the constructor using “placement new” rather than an init
routine. There is no reason not to have global new and delete defined as
well. Your class needs a class delete operator that knows that the
object was constructed using placement new rather than allocated off the
heap. No need for a terminate function - too ugly.

You will however need an init method for any class that needs to do
resource allocations that can fail as there is no c++ exception support
in the kernel, so there is no good way to fail out of the constructor.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolas
Stylianides
Sent: Tuesday, July 26, 2005 10:31 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] DEVICE_EXTENSION + Classes

Gary G. Little wrote:

And of course you did define the constructor of the class you are using
in
your device extension? You’re compiling the source file as a CPP source

file? Are you rolling your own classes or using DriverWorks?

my classes declarations are in *.cpp files.
Nevertheless when Device extension is created there is no way to call
the constractor. So i will use
functions like “Init” and “Terminate”. For heap creations, Mark is
right, i have to declare each class with operator new and delete.
Thank you very much.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Nikolas Stylianides wrote:

Gary G. Little wrote:

> And of course you did define the constructor of the class you are
> using in your device extension? You’re compiling the source file as a
> CPP source file? Are you rolling your own classes or using DriverWorks?
>
>
>
my classes declarations are in *.cpp files.
Nevertheless when Device extension is created there is no way to call
the constractor. So i will use
functions like “Init” and “Terminate”. For heap creations, Mark is
right, i have to declare each class with operator new and delete.
Thank you very much.

Here is an example of using “placement new” to run the constructor of a
device extension. When you pass a parameter to “new” like this, you are
saying “don’t allocate any memory; just use this pointer and do whatever
else you would have done”. FDO_DEVICE_DATA is my device’s extension
class. This is in an AddDevice routine:

PDEVICE_OBJECT fdo;
status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_DATA), NULL,
FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &fdo);
if (!NT_SUCCESS(status))
{ // can’t create device object
KdPrint((DRIVERNAME " - IoCreateDevice failed - %X\n", status));
return status;
} // can’t create device object

// We use placement new here in order to run the constructor.

PFDO_DEVICE_DATA pdx = new(fdo->DeviceExtension) FDO_DEVICE_DATA;
pdx->Signature = DEVICE_EXTENSION_SIGNATURE;


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

You don’t need to use placement new if you don’t want to. It works fine
to just define a global new operator that allocates from non-paged pool
(and one that has an extra parameter for paged pool if you need that
too), and stick a pointer to your “true” device extension in the
DEVICE_OBJECT. For example:

void* __cdecl operator new(size_t size)
{
return operator new(size, NonPagedPool);
}

void* __cdecl operator new(size_t size, POOL_TYPE poolType)
{
// Note: using only 1 constant tag reduces the usefulness of tags,
// but is better than nothing.
return ExAllocatePoolWithTag(poolType, uiSize, ‘gTyM’);
}

void __cdecl operator delete(void* p)
{
if (p) ExFreePoolWithTag(p, ‘gTyM’);
}

status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_DATA*), NULL,
FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &fdo);

fdo->DeviceExtension = new FDO_DEVICE_DATA;

Compared to all the other overhead involved in handling IRPs, calling
your class methods through a (different) pointer is negligible. It also
has the advantage of (slightly) reducing the chance that you’ll scribble
over OS structures if you screw up :-). It does fragment memory a tiny
bit more, but hopefully you aren’t creating and destroying lots of
device objects anyway.

You should definitely read:
http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx. This white
paper contains several things that all C++ driver writers should know
and consider.

Anyway, probably the three most important things to note are: 1) global
objects are not constructed/destructed, 2) no C++ exceptions… only
SEH, which means most use of STL is out, and 3) you have to be very
careful where the compiler puts any little bits of code it decides to
create without your knowledge (such as default copy constructors,
virtual function tables, etc.). I solve the #3 problem by just setting
it up to put *everything* in non-paged pool unless specifically pragma’d
out, which seems to work fine, but it does mean that more of your code
than is absolutely necessary ends up in non-paged pool.

Tim Roberts wrote:

Nikolas Stylianides wrote:

> Gary G. Little wrote:
>
>> And of course you did define the constructor of the class you are
>> using in your device extension? You’re compiling the source file as a
>> CPP source file? Are you rolling your own classes or using DriverWorks?
>>
>>
>>
> my classes declarations are in *.cpp files.
> Nevertheless when Device extension is created there is no way to call
> the constractor. So i will use
> functions like “Init” and “Terminate”. For heap creations, Mark is
> right, i have to declare each class with operator new and delete.
> Thank you very much.

Here is an example of using “placement new” to run the constructor of a
device extension. When you pass a parameter to “new” like this, you are
saying “don’t allocate any memory; just use this pointer and do whatever
else you would have done”. FDO_DEVICE_DATA is my device’s extension
class. This is in an AddDevice routine:

PDEVICE_OBJECT fdo;
status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_DATA), NULL,
FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &fdo);
if (!NT_SUCCESS(status))
{ // can’t create device object
KdPrint((DRIVERNAME " - IoCreateDevice failed - %X\n", status));
return status;
} // can’t create device object

// We use placement new here in order to run the constructor.

PFDO_DEVICE_DATA pdx = new(fdo->DeviceExtension) FDO_DEVICE_DATA;
pdx->Signature = DEVICE_EXTENSION_SIGNATURE;


…/ray..

This won’t work like you think it will. In some stacks and due to some
races, you can receive power and wmi irps after you have processed
IRP_MN_REMOVE_DEVICE. You can receive them b/c these IRPs take a
reference on the device before being sent, so they are sent to a
PDEVICE_OBJECT which is still valid, but mostly destroyed. b/c of this,
your DeviceExtension must have the same lifetime as the PDEVICE_OBJECT
it belongs to. Since the kernel does not have a callback to tell you
when the ref count is truly zero, you can’t touch your DeviceExtension
when processing these irps w/out first making sure you have not yet been
removed…ie, you have to acquire a remove lock before touching the
remainder of the device extension.

You can either hang your class off the DeviceExtension as an allocated
piece of memory or you should use the placement new strategy.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ray Trent
Sent: Tuesday, July 26, 2005 10:38 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DEVICE_EXTENSION + Classes

You don’t need to use placement new if you don’t want to. It works fine
to just define a global new operator that allocates from non-paged pool
(and one that has an extra parameter for paged pool if you need that
too), and stick a pointer to your “true” device extension in the
DEVICE_OBJECT. For example:

void* __cdecl operator new(size_t size)
{
return operator new(size, NonPagedPool);
}

void* __cdecl operator new(size_t size, POOL_TYPE poolType)
{
// Note: using only 1 constant tag reduces the usefulness of tags,
// but is better than nothing.
return ExAllocatePoolWithTag(poolType, uiSize, ‘gTyM’);
}

void __cdecl operator delete(void* p)
{
if (p) ExFreePoolWithTag(p, ‘gTyM’);
}

status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_DATA*), NULL,
FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &fdo);

fdo->DeviceExtension = new FDO_DEVICE_DATA;

Compared to all the other overhead involved in handling IRPs, calling
your class methods through a (different) pointer is negligible. It also
has the advantage of (slightly) reducing the chance that you’ll scribble

over OS structures if you screw up :-). It does fragment memory a tiny
bit more, but hopefully you aren’t creating and destroying lots of
device objects anyway.

You should definitely read:
http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx. This white
paper contains several things that all C++ driver writers should know
and consider.

Anyway, probably the three most important things to note are: 1) global

objects are not constructed/destructed, 2) no C++ exceptions… only
SEH, which means most use of STL is out, and 3) you have to be very
careful where the compiler puts any little bits of code it decides to
create without your knowledge (such as default copy constructors,
virtual function tables, etc.). I solve the #3 problem by just setting
it up to put *everything* in non-paged pool unless specifically pragma’d

out, which seems to work fine, but it does mean that more of your code
than is absolutely necessary ends up in non-paged pool.

Tim Roberts wrote:

Nikolas Stylianides wrote:

> Gary G. Little wrote:
>
>> And of course you did define the constructor of the class you are
>> using in your device extension? You’re compiling the source file as
a
>> CPP source file? Are you rolling your own classes or using
DriverWorks?
>>
>>
>>
> my classes declarations are in *.cpp files.
> Nevertheless when Device extension is created there is no way to call

> the constractor. So i will use
> functions like “Init” and “Terminate”. For heap creations, Mark is
> right, i have to declare each class with operator new and delete.
> Thank you very much.

Here is an example of using “placement new” to run the constructor of
a
device extension. When you pass a parameter to “new” like this, you
are
saying “don’t allocate any memory; just use this pointer and do
whatever
else you would have done”. FDO_DEVICE_DATA is my device’s extension
class. This is in an AddDevice routine:

PDEVICE_OBJECT fdo;
status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_DATA),
NULL,
FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &fdo);
if (!NT_SUCCESS(status))
{ // can’t create device object
KdPrint((DRIVERNAME " - IoCreateDevice failed - %X\n",
status));
return status;
} // can’t create device object

// We use placement new here in order to run the constructor.

PFDO_DEVICE_DATA pdx = new(fdo->DeviceExtension) FDO_DEVICE_DATA;
pdx->Signature = DEVICE_EXTENSION_SIGNATURE;


…/ray..


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Doron Holan wrote:

reference on the device before being sent, so they are sent to a
PDEVICE_OBJECT which is still valid, but mostly destroyed. b/c of this,
your DeviceExtension must have the same lifetime as the PDEVICE_OBJECT
it belongs to. Since the kernel does not have a callback to tell you
when the ref count is truly zero, you can’t touch your DeviceExtension

You can either hang your class off the DeviceExtension as an allocated
piece of memory or you should use the placement new strategy.

Well, ok, you have to be careful (moreso on some stacks than others).
However, you don’t have to be any *more* careful than when using any
*other* allocated memory whose pointer lives in your device extension.

If need be, it can even be set to 0 when deleted so you know not to
touch it. Assuming you don’t need your device extension to handle
power/WMI IRPs that occur after your device is removed, that is… but
again, you have that problem with any allocated memory.

BTW, you might want to ask the documentation guys to note this gotcha in
the DDK docs for IRP_MN_REMOVE_DEVICE (and/or associated referenced pages).

It’s kind of mean to tell driver writers in the docs “Before a driver
returns success for an IRP_MN_REMOVE_DEVICE request, it must ensure that
all resources for the device have been released” and then have the OS
touch that device later in a way that might potentially require one or
more of those resources in order to make the response.

I assume, BTW, that one is supposed to either just fail or succeed those
WMI and power IRPs that come after your device is removed? At least that
sounds like the most obvious answer to me… How could you do anything
else with a device that has had all its resources released? Again, if
something else is needed it really ought to be documented.

…/ray..

Now, wait a second. I’m still trying to come to terms with WDM/PNP, so bear
with me if this sounds incredibly stupid, but…

Aren’t you supposed to delete your FDO in response to IRP_MN_REMOVE_DEVICE?
After the IoDeleteDevice call returns, shouldn’t the I/O Manager guarantee
that no more IRPs – of ANY kind – will be delivered to that deleted
device?

I’m astonished at how bad the NT device model is with respect to memory
ownership.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ray Trent
Sent: Tuesday, July 26, 2005 5:11 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DEVICE_EXTENSION + Classes

Doron Holan wrote:

reference on the device before being sent, so they are sent to a
PDEVICE_OBJECT which is still valid, but mostly destroyed. b/c of
this, your DeviceExtension must have the same lifetime as the
PDEVICE_OBJECT it belongs to. Since the kernel does not have a
callback to tell you when the ref count is truly zero, you can’t touch
your DeviceExtension …
You can either hang your class off the DeviceExtension as an allocated
piece of memory or you should use the placement new strategy.

Well, ok, you have to be careful (moreso on some stacks than others).
However, you don’t have to be any *more* careful than when using any
*other* allocated memory whose pointer lives in your device extension.

If need be, it can even be set to 0 when deleted so you know not to touch
it. Assuming you don’t need your device extension to handle power/WMI IRPs
that occur after your device is removed, that is… but again, you have that
problem with any allocated memory.

BTW, you might want to ask the documentation guys to note this gotcha in the
DDK docs for IRP_MN_REMOVE_DEVICE (and/or associated referenced pages).

It’s kind of mean to tell driver writers in the docs “Before a driver
returns success for an IRP_MN_REMOVE_DEVICE request, it must ensure that all
resources for the device have been released” and then have the OS touch that
device later in a way that might potentially require one or more of those
resources in order to make the response.

I assume, BTW, that one is supposed to either just fail or succeed those WMI
and power IRPs that come after your device is removed? At least that sounds
like the most obvious answer to me… How could you do anything else with a
device that has had all its resources released? Again, if something else is
needed it really ought to be documented.

…/ray..


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stonestreetone.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

No. Costruct it itself by using something like
(&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit constructor call syntax,
which is intended for C++ to construct the object as a part of the more complex
data structure which is not allocated by you.

I would avoid using constructors in such contexts at all.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Nikolas Stylianides”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, July 26, 2005 5:54 PM
Subject: [ntdev] DEVICE_EXTENSION + Classes

> Hi there, one of my DEVICE_EXTENSION parameters is an object of some class.
> When the system initializes the device_extension calls the constractor
> of the class as well?
> I think not.
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

IoDeleteDevice just decrements the ref count on the object. It also
sets a flag indicating that UM I/O should fail. Additionally, you can’t
get to remove with open handles on the device so UM i/o can’t get to you
anwyas. Both wmi and power just use IoCallDriver and do not check the
flag (there is an inherit race there anways).

D

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Tuesday, July 26, 2005 2:19 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DEVICE_EXTENSION + Classes

Now, wait a second. I’m still trying to come to terms with WDM/PNP, so
bear
with me if this sounds incredibly stupid, but…

Aren’t you supposed to delete your FDO in response to
IRP_MN_REMOVE_DEVICE?
After the IoDeleteDevice call returns, shouldn’t the I/O Manager
guarantee
that no more IRPs – of ANY kind – will be delivered to that deleted
device?

I’m astonished at how bad the NT device model is with respect to memory
ownership.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ray Trent
Sent: Tuesday, July 26, 2005 5:11 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DEVICE_EXTENSION + Classes

Doron Holan wrote:

reference on the device before being sent, so they are sent to a
PDEVICE_OBJECT which is still valid, but mostly destroyed. b/c of
this, your DeviceExtension must have the same lifetime as the
PDEVICE_OBJECT it belongs to. Since the kernel does not have a
callback to tell you when the ref count is truly zero, you can’t touch

your DeviceExtension …
You can either hang your class off the DeviceExtension as an allocated

piece of memory or you should use the placement new strategy.

Well, ok, you have to be careful (moreso on some stacks than others).
However, you don’t have to be any *more* careful than when using any
*other* allocated memory whose pointer lives in your device extension.

If need be, it can even be set to 0 when deleted so you know not to
touch
it. Assuming you don’t need your device extension to handle power/WMI
IRPs
that occur after your device is removed, that is… but again, you have
that
problem with any allocated memory.

BTW, you might want to ask the documentation guys to note this gotcha in
the
DDK docs for IRP_MN_REMOVE_DEVICE (and/or associated referenced pages).

It’s kind of mean to tell driver writers in the docs “Before a driver
returns success for an IRP_MN_REMOVE_DEVICE request, it must ensure that
all
resources for the device have been released” and then have the OS touch
that
device later in a way that might potentially require one or more of
those
resources in order to make the response.

I assume, BTW, that one is supposed to either just fail or succeed those
WMI
and power IRPs that come after your device is removed? At least that
sounds
like the most obvious answer to me… How could you do anything else
with a
device that has had all its resources released? Again, if something else
is
needed it really ought to be documented.

…/ray..


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stonestreetone.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

You can fail the irps in this case. You complete the irp with the
failure code that IoAcquireRemoveLock returned to you.

You synchronize the access to allocated memory off of the device
extension by acquiring the remlock before any other processing occurs.
By acquiring the remlock, you block remove device from releasing the
memory you are touching until you release the remlock (b/c the remove
path calls IoReleaseRemoveLockAndWait which blocks on the ref you took
until it is released.) as long as you have a remlock reference, you can
touch the memory (assuming there is no other type of synchronization
that is required).

The docs will be updated. A driver tip is in the works and will show up
on WHDC as well.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ray Trent
Sent: Tuesday, July 26, 2005 2:11 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DEVICE_EXTENSION + Classes

Doron Holan wrote:

reference on the device before being sent, so they are sent to a
PDEVICE_OBJECT which is still valid, but mostly destroyed. b/c of
this,
your DeviceExtension must have the same lifetime as the PDEVICE_OBJECT
it belongs to. Since the kernel does not have a callback to tell you
when the ref count is truly zero, you can’t touch your DeviceExtension

You can either hang your class off the DeviceExtension as an allocated
piece of memory or you should use the placement new strategy.

Well, ok, you have to be careful (moreso on some stacks than others).
However, you don’t have to be any *more* careful than when using any
*other* allocated memory whose pointer lives in your device extension.

If need be, it can even be set to 0 when deleted so you know not to
touch it. Assuming you don’t need your device extension to handle
power/WMI IRPs that occur after your device is removed, that is… but
again, you have that problem with any allocated memory.

BTW, you might want to ask the documentation guys to note this gotcha in

the DDK docs for IRP_MN_REMOVE_DEVICE (and/or associated referenced
pages).

It’s kind of mean to tell driver writers in the docs "Before a driver
returns success for an IRP_MN_REMOVE_DEVICE request, it must ensure that

all resources for the device have been released" and then have the OS
touch that device later in a way that might potentially require one or
more of those resources in order to make the response.

I assume, BTW, that one is supposed to either just fail or succeed those

WMI and power IRPs that come after your device is removed? At least that

sounds like the most obvious answer to me… How could you do anything
else with a device that has had all its resources released? Again, if
something else is needed it really ought to be documented.

…/ray..


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Maxim S. Shatskih wrote:

No. Costruct it itself by using something like
(&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit constructor call syntax,
which is intended for C++ to construct the object as a part of the more complex
data structure which is not allocated by you.

That’s much more obscure than the equivalent “placement new” syntax I
posted earlier today.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Indeed, placement new is the documented standard way to construct a
preallocated object.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Tuesday, July 26, 2005 7:18 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] DEVICE_EXTENSION + Classes

Maxim S. Shatskih wrote:

> No. Costruct it itself by using something like
>(&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit
constructor call
>syntax, which is intended for C++ to construct the object as
a part of
>the more complex data structure which is not allocated by you.
>
>

That’s much more obscure than the equivalent “placement new”
syntax I posted earlier today.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@hollistech.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Mark Roddy wrote:

Indeed, placement new is the documented standard way to construct a
preallocated object.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

>-----Original Message-----
>From: xxxxx@lists.osr.com
>[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
>Sent: Tuesday, July 26, 2005 7:18 PM
>To: Windows System Software Devs Interest List
>Subject: Re: [ntdev] DEVICE_EXTENSION + Classes
>
>Maxim S. Shatskih wrote:
>
>
>
>> No. Costruct it itself by using something like
>>(&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit
>>
>>
>constructor call
>
>
>>syntax, which is intended for C++ to construct the object as
>>
>>
>a part of
>
>
>>the more complex data structure which is not allocated by you.
>>
>>
>>
>>
>That’s much more obscure than the equivalent “placement new”
>syntax I posted earlier today.
>
>–
>Tim Roberts, xxxxx@probo.com
>Providenza & Boekelheide, Inc.
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hollistech.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@4plus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I prefer also the placement new method. It is not in my concern to
allocate and deallocate memory. Just need to call the constructor.
I noticed that i must not use the delete method. Just call the
p->~Destructor() of my class.

Further more. My extension class has other objects as well.
Will their constructor be called or do i have to follow the same
mechanism like here?

Implement a delete operator for your class that does not free to pool and
then just do the normal thing: delete object.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
Nikolas Stylianides
Sent: Wednesday, July 27, 2005 4:07 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] DEVICE_EXTENSION + Classes

Mark Roddy wrote:

>Indeed, placement new is the documented standard way to construct a
>preallocated object.
>
>=====================
>Mark Roddy DDK MVP
>Windows 2003/XP/2000 Consulting
>Hollis Technology Solutions 603-321-1032 www.hollistech.com
>
>
>
>>-----Original Message-----
>>From: xxxxx@lists.osr.com
>>[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
>>Sent: Tuesday, July 26, 2005 7:18 PM
>>To: Windows System Software Devs Interest List
>>Subject: Re: [ntdev] DEVICE_EXTENSION + Classes
>>
>>Maxim S. Shatskih wrote:
>>
>>
>>
>>> No. Costruct it itself by using something like
>>>(&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit
>>>
>>>
>>constructor call
>>
>>
>>>syntax, which is intended for C++ to construct the object as
>>>
>>>
>>a part of
>>
>>
>>>the more complex data structure which is not allocated by you.
>>>
>>>
>>>
>>>
>>That’s much more obscure than the equivalent “placement new”
>>syntax I posted earlier today.
>>
>>–
>>Tim Roberts, xxxxx@probo.com
>>Providenza & Boekelheide, Inc.
>>
>>
>>—
>>Questions? First check the Kernel Driver FAQ at
>>http://www.osronline.com/article.cfm?id=256
>>
>>You are currently subscribed to ntdev as: xxxxx@hollistech.com To
>>unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@4plus.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
I prefer also the placement new method. It is not in my
concern to allocate and deallocate memory. Just need to call
the constructor.
I noticed that i must not use the delete method. Just call the
p->~Destructor() of my class.

Further more. My extension class has other objects as well.
Will their constructor be called or do i have to follow the same
mechanism like here?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@hollistech.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Mark Roddy wrote:

Implement a delete operator for your class that does not free to pool and
then just do the normal thing: delete object.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

>-----Original Message-----
>From: xxxxx@lists.osr.com
>[mailto:xxxxx@lists.osr.com] On Behalf Of
>Nikolas Stylianides
>Sent: Wednesday, July 27, 2005 4:07 AM
>To: Windows System Software Devs Interest List
>Subject: Re: [ntdev] DEVICE_EXTENSION + Classes
>
>Mark Roddy wrote:
>
>
>
>>Indeed, placement new is the documented standard way to construct a
>>preallocated object.
>>
>>=====================
>>Mark Roddy DDK MVP
>>Windows 2003/XP/2000 Consulting
>>Hollis Technology Solutions 603-321-1032 www.hollistech.com
>>
>>
>>
>>
>>
>>>-----Original Message-----
>>>From: xxxxx@lists.osr.com
>>>[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
>>>Sent: Tuesday, July 26, 2005 7:18 PM
>>>To: Windows System Software Devs Interest List
>>>Subject: Re: [ntdev] DEVICE_EXTENSION + Classes
>>>
>>>Maxim S. Shatskih wrote:
>>>
>>>
>>>
>>>
>>>
>>>> No. Costruct it itself by using something like
>>>>(&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit
>>>>
>>>>
>>>>
>>>>
>>>constructor call
>>>
>>>
>>>
>>>
>>>>syntax, which is intended for C++ to construct the object as
>>>>
>>>>
>>>>
>>>>
>>>a part of
>>>
>>>
>>>
>>>
>>>>the more complex data structure which is not allocated by you.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>That’s much more obscure than the equivalent “placement new”
>>>syntax I posted earlier today.
>>>
>>>–
>>>Tim Roberts, xxxxx@probo.com
>>>Providenza & Boekelheide, Inc.
>>>
>>>
>>>—
>>>Questions? First check the Kernel Driver FAQ at
>>>http://www.osronline.com/article.cfm?id=256
>>>
>>>You are currently subscribed to ntdev as: xxxxx@hollistech.com To
>>>unsubscribe send a blank email to xxxxx@lists.osr.com
>>>
>>>
>>>
>>>
>>>
>>
>>—
>>Questions? First check the Kernel Driver FAQ at
>>http://www.osronline.com/article.cfm?id=256
>>
>>You are currently subscribed to ntdev as: xxxxx@4plus.com To
>>unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>>
>>
>I prefer also the placement new method. It is not in my
>concern to allocate and deallocate memory. Just need to call
>the constructor.
>I noticed that i must not use the delete method. Just call the
>p->~Destructor() of my class.
>
>Further more. My extension class has other objects as well.
>Will their constructor be called or do i have to follow the same
>mechanism like here?
>
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hollistech.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@4plus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I use no global new and deletes.
i implemented for my extension class:

  1. new(size_t size, void* p){return p;}
  2. delete(void*,void*){return;}
  3. delete(void*){return;}

It works just fine. I was glad to see that all objects contained in
extension class instantiated like normal C++ without this extra feature
in their class definitions.

What would i need a global new and delete?

Nikolas Stylianides wrote:

Mark Roddy wrote:

> Implement a delete operator for your class that does not free to pool
> and
> then just do the normal thing: delete object.
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Nikolas
>> Stylianides
>> Sent: Wednesday, July 27, 2005 4:07 AM
>> To: Windows System Software Devs Interest List
>> Subject: Re: [ntdev] DEVICE_EXTENSION + Classes
>>
>> Mark Roddy wrote:
>>
>>
>>
>>> Indeed, placement new is the documented standard way to construct a
>>> preallocated object.
>>>
>>> =====================
>>> Mark Roddy DDK MVP
>>> Windows 2003/XP/2000 Consulting
>>> Hollis Technology Solutions 603-321-1032 www.hollistech.com
>>>
>>>
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: xxxxx@lists.osr.com
>>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
>>>> Sent: Tuesday, July 26, 2005 7:18 PM
>>>> To: Windows System Software Devs Interest List
>>>> Subject: Re: [ntdev] DEVICE_EXTENSION + Classes
>>>>
>>>> Maxim S. Shatskih wrote:
>>>>
>>>>
>>>>
>>>>
>>>>> No. Costruct it itself by using something like
>>>>> (&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit
>>>>>
>>>>>
>>>>
>>>> constructor call
>>>>
>>>>
>>>>
>>>>> syntax, which is intended for C++ to construct the object as
>>>>>
>>>>>
>>>>
>>>> a part of
>>>>
>>>>
>>>>
>>>>> the more complex data structure which is not allocated by you.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> That’s much more obscure than the equivalent “placement new”
>>>> syntax I posted earlier today.
>>>>
>>>> –
>>>> Tim Roberts, xxxxx@probo.com
>>>> Providenza & Boekelheide, Inc.
>>>>
>>>>
>>>> —
>>>> Questions? First check the Kernel Driver FAQ at
>>>> http://www.osronline.com/article.cfm?id=256
>>>>
>>>> You are currently subscribed to ntdev as: xxxxx@hollistech.com To
>>>> unsubscribe send a blank email to xxxxx@lists.osr.com
>>>>
>>>>
>>>>
>>>
>>>
>>> —
>>> Questions? First check the Kernel Driver FAQ at
>>> http://www.osronline.com/article.cfm?id=256
>>>
>>> You are currently subscribed to ntdev as: xxxxx@4plus.com To
>>> unsubscribe send a blank email to xxxxx@lists.osr.com
>>>
>>>
>>>
>>>
>>>
>>
>> I prefer also the placement new method. It is not in my concern to
>> allocate and deallocate memory. Just need to call the constructor.
>> I noticed that i must not use the delete method. Just call the
>> p->~Destructor() of my class.
>>
>> Further more. My extension class has other objects as well.
>> Will their constructor be called or do i have to follow the same
>> mechanism like here?
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: xxxxx@hollistech.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@4plus.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
I use no global new and deletes.
i implemented for my extension class:

  1. new(size_t size, void* p){return p;}
  2. delete(void*,void*){return;}
  3. delete(void*){return;}

It works just fine. I was glad to see that all objects contained in
extension class instantiated like normal C++ without this extra
feature in their class definitions.

What would i need a global new and delete?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@4plus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

OK is redigulous to reply to myself but the fact is that i use global
new and delete. I thought i erase the files but i did not. No way of
linker to know how to link them if global new and delete are not there.

Sorry.

If you call the destructor on your class explicitly, the compiler will
make sure that all objects contained in the extension will also be
destructed.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolas
Stylianides
Sent: Wednesday, July 27, 2005 1:07 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] DEVICE_EXTENSION + Classes

Mark Roddy wrote:

Indeed, placement new is the documented standard way to construct a
preallocated object.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

>-----Original Message-----
>From: xxxxx@lists.osr.com
>[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
>Sent: Tuesday, July 26, 2005 7:18 PM
>To: Windows System Software Devs Interest List
>Subject: Re: [ntdev] DEVICE_EXTENSION + Classes
>
>Maxim S. Shatskih wrote:
>
>
>
>> No. Costruct it itself by using something like
>>(&(MyDevExt->MyObj)).CMyObj::CMyObj() - the explicit
>>
>>
>constructor call
>
>
>>syntax, which is intended for C++ to construct the object as
>>
>>
>a part of
>
>
>>the more complex data structure which is not allocated by you.
>>
>>
>>
>>
>That’s much more obscure than the equivalent “placement new”
>syntax I posted earlier today.
>
>–
>Tim Roberts, xxxxx@probo.com
>Providenza & Boekelheide, Inc.
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hollistech.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@4plus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I prefer also the placement new method. It is not in my concern to
allocate and deallocate memory. Just need to call the constructor.
I noticed that i must not use the delete method. Just call the
p->~Destructor() of my class.

Further more. My extension class has other objects as well.
Will their constructor be called or do i have to follow the same
mechanism like here?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com