Placement new operator in a driver

I have nothing new, interesting, or intelligent to add to this thread (so as not to ruin the current trend), but I just wanted to have the honor of the 100th reply.

This thread is now by far the longest single thread in recorded NTDEV history. The set of x64 driver signing threads was longer, but that conversation stretched across several individual topics.

Peter
OSR

P.S. C++ is shite, and should be relegated to use only in the vast dung heap of GUI apps. If we have to have an oo language in kernel-mode, let’s get over it and go to C# which does’t suck nearly as much as the hacked-up, halfway correct, miserably ugly measures of C++. See, I TOLD you I didn’t have anything intelligent to add.

I would request that OSR create a new list called, NTDEBATE. I believe the
list slaves at OSR who work tirelessly to provide these forums should have
the right to assign a thread to NTDEBATE. It will require some smarts in
the list management to redirect the repsonces to the old items, but this
will give us a way to have these interesting discussions, without having
these huge threads in the regular forum.

This will mean the regular forums will be there to provide questions and
answers without denying anyone the enjoyment ot these long debates.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

wrote in message news:xxxxx@ntdev…
>I have nothing new, interesting, or intelligent to add to this thread (so
>as not to ruin the current trend), but I just wanted to have the honor of
>the 100th reply.
>
> This thread is now by far the longest single thread in recorded NTDEV
> history. The set of x64 driver signing threads was longer, but that
> conversation stretched across several individual topics.
>
> Peter
> OSR
>
> P.S. C++ is shite, and should be relegated to use only in the vast dung
> heap of GUI apps. If we have to have an oo language in kernel-mode, let’s
> get over it and go to C# which does’t suck nearly as much as the
> hacked-up, halfway correct, miserably ugly measures of C++. See, I TOLD
> you I didn’t have anything intelligent to add.
>
>

Because you can’t tell what the hell is going on by looking at the
calling code (vs the impl).

CFoo f;

DoSomething(f);

Is that a ref and f has changed afterward? Was f passed by value? Is
that a const ref and f has not changed? No references is purely so that
when you look at the callsite of a function, you know it is going to
change the object, e.g.

DoSomething(&f);

This is purely a coding convention, it has nothing to do with the
compiler.

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
Sent: Thursday, April 27, 2006 6:29 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Placement new operator in a driver

DORON:

Why no references? Is that just a semantics/convenience/convention (i.
e. - because it doesn’t explicitly look like a pointer) issue, or is it
a compiler/kernel thing?

Just curious.

MM

>> xxxxx@microsoft.com 2006-04-26 23:27 >>>
Borrow? You surely jest ;). Design patterns are patterns for a
reason, they are useful. Yes, the underlying implementation of KMDF is
written in C++, but under some very strict rules. No references, no
templates, no overloaded operators. Basically, we use C++ for vtables
and vtables only.

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of hanzhu
Sent: Wednesday, April 26, 2006 9:14 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Is KMDF developed in C++ as Mark has pointed out?
I always suppose that KMDF has just borrowed some ideas and design
patterns from the OO programming world!!! :slight_smile:
Doron, Can you clarify this question for our newbies?


Best Regards,
hanzhu

Mark Roddy :

By the way, several Microsoft kernel components are developed using
C++, for
example KMDF.

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

> C has been designed as lower lever, closer to machine
> semantics language.
> C++ has been designed for usermode. The “better C” approach
> did not work
> for many reasons mentioned in this thread, especially by Don Burn.
> The Embedded C++ project failed.
> Do you see much C++ in Linux kernel? nope.
> It’s time for conclusions… C++ just doesn’t have it.
> Maybe C# will be the next “better C”.
>
> Regards,
> --PA
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online
> at http://www.osronline.com/page.cfm?name=ListServer
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

DORON:

Thanks,

MM

>> xxxxx@microsoft.com 2006-04-27 12:16 >>>
Because you can’t tell what the hell is going on by looking at the
calling code (vs the impl).

CFoo f;

DoSomething(f);

Is that a ref and f has changed afterward? Was f passed by value? Is
that a const ref and f has not changed? No references is purely so
that
when you look at the callsite of a function, you know it is going to
change the object, e.g.

DoSomething(&f);

This is purely a coding convention, it has nothing to do with the
compiler.

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
Sent: Thursday, April 27, 2006 6:29 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Placement new operator in a driver

DORON:

Why no references? Is that just a semantics/convenience/convention
(i.
e. - because it doesn’t explicitly look like a pointer) issue, or is
it
a compiler/kernel thing?

Just curious.

MM

>> xxxxx@microsoft.com 2006-04-26 23:27 >>>
Borrow? You surely jest ;). Design patterns are patterns for a
reason, they are useful. Yes, the underlying implementation of KMDF
is
written in C++, but under some very strict rules. No references, no
templates, no overloaded operators. Basically, we use C++ for vtables
and vtables only.

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of hanzhu
Sent: Wednesday, April 26, 2006 9:14 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Is KMDF developed in C++ as Mark has pointed out?
I always suppose that KMDF has just borrowed some ideas and design
patterns from the OO programming world!!! :slight_smile:
Doron, Can you clarify this question for our newbies?


Best Regards,
hanzhu

Mark Roddy :

By the way, several Microsoft kernel components are developed using
C++, for
example KMDF.

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

> C has been designed as lower lever, closer to machine
> semantics language.
> C++ has been designed for usermode. The “better C” approach
> did not work
> for many reasons mentioned in this thread, especially by Don Burn.
> The Embedded C++ project failed.
> Do you see much C++ in Linux kernel? nope.
> It’s time for conclusions… C++ just doesn’t have it.
> Maybe C# will be the next “better C”.
>
> Regards,
> --PA
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online
> at http://www.osronline.com/page.cfm?name=ListServer
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

There is a whitepaper on whdc that discusses this

http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of hanzhu
Sent: Thursday, April 27, 2006 3:52 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Got it!
Doron, can you sum up these rules we should follow if we want to develop
our kernel mode program safely using c++? I have read most of the posts
in this thread, however, I’m afraid that I missed something! :slight_smile:
My personnel attitude from my poor experience and your gurus discussion
about this topic is C is much straight and clear for developing driver.
You also could write your program much quick in C if you have to do it
from scratch. But kernel program based on C++ is more maintainable and a
little robust(This factor depends much on developer’s skill. But strict
type check etc. will help you achieve this.) Oh, there is another major
advantage for C++ since it makes CODE REUSE easily!

Thanks a lot!


Best Regards,
hanzhu

Doron Holan $B> Borrow? You surely jest ;). Design patterns are patterns for a reason, they are useful. Yes, the underlying implementation of KMDF is written in C++, but under some very strict rules. No references, no templates, no overloaded operators. Basically, we use C++ for vtables and vtables only.
>
> d
>
> – I can spell, I just can’t type.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of hanzhu
> Sent: Wednesday, April 26, 2006 9:14 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] Placement new operator in a driver
>
> Is KMDF developed in C++ as Mark has pointed out?
> I always suppose that KMDF has just borrowed some ideas and design
> patterns from the OO programming world!!! :slight_smile:
> Doron, Can you clarify this question for our newbies?
>
> _______________________________________________________
> Best Regards,
> hanzhu
>
>
> Mark Roddy $B>> By the way, several Microsoft kernel components are developed using C++, for
>> example KMDF.
>>
>>
>> =====================
>> Mark Roddy DDK MVP
>> Windows 2003/XP/2000 Consulting
>> Hollis Technology Solutions 603-321-1032
>> www.hollistech.com
>>
>>
>>> C has been designed as lower lever, closer to machine
>>> semantics language.
>>> C++ has been designed for usermode. The “better C” approach
>>> did not work
>>> for many reasons mentioned in this thread, especially by Don Burn.
>>> The Embedded C++ project failed.
>>> Do you see much C++ in Linux kernel? nope.
>>> It’s time for conclusions… C++ just doesn’t have it.
>>> Maybe C# will be the next “better C”.
>>>
>>> Regards,
>>> --PA
>>>
>>>
>>>
>>> —
>>> Questions? First check the Kernel Driver FAQ at
>>> http://www.osronline.com/article.cfm?id=256
>>>
>>> To unsubscribe, visit the List Server section of OSR Online
>>> at http://www.osronline.com/page.cfm?name=ListServer
>>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>>
>> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>>
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>


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

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

hanzhu wrote:

But kernel program based on C++ is more maintainable and a
little robust(This factor depends much on developer’s skill. But strict
type check etc. will help you achieve this.) Oh, there is another major
advantage for C++ since it makes CODE REUSE easily!

I really have to take exception to the above statements. We have already
discussed that the strict type checking of C++ can be reached by /W4 on the
C compiler. There is no evidence that C++ makes code more robust in the
kernel, and plenty of potential problems as mentioned in this thread. Note:
I have while analyzing customers code found the misplaced autogenerated
code.

On code resuse, this highly depends on the body of code available, and most
important the skill of the developer. The language has little to do with
the ability to reuse code.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

I would have to agree with Don. On my previous project (Bluetooth), we
had a tremendous amount of reusable code that was shared among 4 or 5
drivers and it was all written in C (and it was object based as well in
places).

The language you use is the language that makes you most productive and
meets your goals, can be maintained over time, and meets the skill level
of the team. This can change from project to project and environment to
environment. There is no blanket answer that is one size fits all when
you take this into account (although I personally still prefer C for
almost all of my work :wink: ).

As an example, KMDF has a header generation toolset which we use to
autogenerate and version our headers. It serializes data into a common
XML file and different tools process it to generate different headers.
This was written entirely in C#. C# was perfect for the job: it runs
only in UM, it is not perf sensitive,it allows for a great deal of
experimentation and change in the toolset, and junior developers can
take update the tools b/c it is using a language that can be easily
groked.

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Thursday, April 27, 2006 10:17 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Placement new operator in a driver

hanzhu wrote:

But kernel program based on C++ is more maintainable and a
little robust(This factor depends much on developer’s skill. But
strict
type check etc. will help you achieve this.) Oh, there is another
major
advantage for C++ since it makes CODE REUSE easily!

I really have to take exception to the above statements. We have
already
discussed that the strict type checking of C++ can be reached by /W4 on
the
C compiler. There is no evidence that C++ makes code more robust in
the
kernel, and plenty of potential problems as mentioned in this thread.
Note:
I have while analyzing customers code found the misplaced autogenerated
code.

On code resuse, this highly depends on the body of code available, and
most
important the skill of the developer. The language has little to do
with
the ability to reuse code.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

“Doron Holan” wrote in message
news:xxxxx@ntdev…
> Borrow? You surely jest ;). Design patterns are patterns for a reason,
> they are useful. Yes, the underlying implementation of KMDF is written in
> C++, but under some very strict rules. No references, no templates, no
> overloaded operators. Basically, we use C++ for vtables and vtables only.

Out of curiosity: what is so special about using vtables, and what does the
KMDF use them for?



Kind regards,
Bruno van Dooren
xxxxx@hotmail.com
Remove only “_nos_pam”

Doron Holan wrote:

The language you use is the language that makes you most productive and
meets your goals, can be maintained over time, and meets the skill level
of the team. This can change from project to project and environment to
environment.

Absolutely correct. This is perhaps the wisest nugget that has been
presented throughout this long and unproductive thread. Everything else
is just religion, and no rational debate will ever convince someone to
convert.

Now, let’s get back to something less controversial, like debating
whether vim is better than emacs.


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

Bruno van Dooren wrote:

“Doron Holan” wrote in message
>news:xxxxx@ntdev…
>
>
>>Borrow? You surely jest ;). Design patterns are patterns for a reason,
>>they are useful. Yes, the underlying implementation of KMDF is written in
>>C++, but under some very strict rules. No references, no templates, no
>>overloaded operators. Basically, we use C++ for vtables and vtables only.
>>
>>
>
>Out of curiosity: what is so special about using vtables, and what does the
>KMDF use them for?
>
>

Encapsulation and polymorphism, I imagine. Vtables are the magic that
leads to interfaces and COM, and prograrmming by interface can be very
productive.


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

Vtables == virtual functions. We don’t do COM style pure abstract
interfaces, but we have a root object (FxObject) that is the basis for
all other KMDF objects. It has the std AddRef/Release/QI on it plus a
couple of other virtuals. Almost all of KMDF is pure function call that
is not virtual, there is only one object which uses virtual functions
for its heavy lifting.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, April 27, 2006 1:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Bruno van Dooren wrote:

“Doron Holan” wrote in message
>news:xxxxx@ntdev…
>
>
>>Borrow? You surely jest ;). Design patterns are patterns for a
reason,
>>they are useful. Yes, the underlying implementation of KMDF is
written in
>>C++, but under some very strict rules. No references, no templates,
no
>>overloaded operators. Basically, we use C++ for vtables and vtables
only.
>>
>>
>
>Out of curiosity: what is so special about using vtables, and what does
the
>KMDF use them for?
>
>

Encapsulation and polymorphism, I imagine. Vtables are the magic that
leads to interfaces and COM, and prograrmming by interface can be very
productive.


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


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> That’s what I had in mind when I talked about language

features’ extension, attributes in the first place.

#pragma alloc_text actually is an attribute, but neither
C nor C++ know about that.

Reflection would be also nice in the kernel (as it is in UM).

For what? First of all, reflection breaks OO paradigm. It provocates the non
polymorphic programming styles, and is very rarely useful. Stroustrup even did
not include any reflection in early C++, when he (and not the ANSI commitee
gang) was the owner of the language.

Wow! KM port of mscorelib is simple???

According to what Scott Nonnenberg (one of the C#/.NET program managers) told
me on MVP Open Days in Prague Mar 05 - there are no MS’s plans to support CLR
in the kernel.

IMHO developing C# - styled dialect for KM would be quite
an undertaking.

…and will give no value :slight_smile:

At least a (theoretical?) chance to reflect the new/updated
non-sequential reality.

There is no new reality in the kernel. Sorry.

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

Doron

Just to be curious what has been your approach to resoutce allocation
failure? Typical in C++ (and otehr o-o) is that constructor which fails due
to resource allocation failure throws exception and the exception is caught
and ‘handled’ for some value of ‘handled’. Now of course in kernel we have
no C++ exceptions. First case is the object itself cannot be allocated;
simple case because ctor can return null. Second case is allocation of the
object succeeds but ctor performs secondary allocations which fail; not so
simple case.

Cheers
Lyndon

“Doron Holan” wrote in message
news:xxxxx@ntdev…
Vtables == virtual functions. We don’t do COM style pure abstract
interfaces, but we have a root object (FxObject) that is the basis for
all other KMDF objects. It has the std AddRef/Release/QI on it plus a
couple of other virtuals. Almost all of KMDF is pure function call that
is not virtual, there is only one object which uses virtual functions
for its heavy lifting.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, April 27, 2006 1:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Bruno van Dooren wrote:

>“Doron Holan” wrote in message
>news:xxxxx@ntdev…
>
>
>>Borrow? You surely jest ;). Design patterns are patterns for a
reason,
>>they are useful. Yes, the underlying implementation of KMDF is
written in
>>C++, but under some very strict rules. No references, no templates,
no
>>overloaded operators. Basically, we use C++ for vtables and vtables
only.
>>
>>
>
>Out of curiosity: what is so special about using vtables, and what does
the
>KMDF use them for?
>
>

Encapsulation and polymorphism, I imagine. Vtables are the magic that
leads to interfaces and COM, and prograrmming by interface can be very
productive.


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


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> drivers for our virtual devices on plain C.

  • Plain C would increase time-to-market in *several* times.

Have you really tried this? Looks like a myth you believe. Well, at least this
does not lead to issues :slight_smile: your right :slight_smile:

  • The codebase in C would be hardly manageable due to its “fragility” in
    terms of bugs.

C++ is by far more fragile. Let’s took the dreaded “fragile base class” issue,
for instance.

  • With C++, we work on the “write-and-forget” basis. We usually get back to
    old code only to add new functionality.

Reachable in C too, and easier then in C++. The C++ features does not help to
reach this. This is only due to good professional skills of the developers.
Good developer will write good code in any language.

  • Most of the bugs are usually typos, hardware or third party related.

Correct. So is with my C code. Now note - typo in C++ can be much harder to
find.

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

>some very strict rules. No references, no templates, no overloaded operators.

Basically, we use C++ for vtables and vtables only.

Even no smart pointers?

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

> from scratch. But kernel program based on C++ is more

maintainable and a
little robust(This factor depends much on developer’s

C is always more maintanable then C++. Only the very, very great developer
experience can make this not true.

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

> 1. It would be nice if a project was time dependant on “code typing,”

but is this realistic. Actually, it would suck, because it would be
really, really boring. Perhaps I’m alone in this, but projects always
depend massively on debugging, with only redesign due to client wishes
usually exceeding it.

UI.
Debugging time is short - all bugs are immediately visible.

perpetrated the idea that C++ is trivial and, in fact, cures cancer.

No. It is trivial to abuse :slight_smile: and hard to use properly :slight_smile:

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

  1. We don’t use C++ EH
  2. All calls to new() are checked for NULL. Since we wrote the
    operator new(), we know it doesn’t throw
  3. if the object itself needs to allocate more memory then just itself,
    it does not do it in its ctor(). Rather, the object will have an
    NTSTATUS Initialize(…) call in which the caller must call and check
    the return value on. This is codified in our style guidelines doc and
    must be followed in all of our code ;).

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J. Clarke
Sent: Thursday, April 27, 2006 2:28 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Placement new operator in a driver

Doron

Just to be curious what has been your approach to resoutce allocation
failure? Typical in C++ (and otehr o-o) is that constructor which fails
due
to resource allocation failure throws exception and the exception is
caught
and ‘handled’ for some value of ‘handled’. Now of course in kernel we
have
no C++ exceptions. First case is the object itself cannot be allocated;
simple case because ctor can return null. Second case is allocation of
the
object succeeds but ctor performs secondary allocations which fail; not
so
simple case.

Cheers
Lyndon

“Doron Holan” wrote in message
news:xxxxx@ntdev…
Vtables == virtual functions. We don’t do COM style pure abstract
interfaces, but we have a root object (FxObject) that is the basis for
all other KMDF objects. It has the std AddRef/Release/QI on it plus a
couple of other virtuals. Almost all of KMDF is pure function call that
is not virtual, there is only one object which uses virtual functions
for its heavy lifting.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, April 27, 2006 1:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Bruno van Dooren wrote:

>“Doron Holan” wrote in message
>news:xxxxx@ntdev…
>
>
>>Borrow? You surely jest ;). Design patterns are patterns for a
reason,
>>they are useful. Yes, the underlying implementation of KMDF is
written in
>>C++, but under some very strict rules. No references, no templates,
no
>>overloaded operators. Basically, we use C++ for vtables and vtables
only.
>>
>>
>
>Out of curiosity: what is so special about using vtables, and what does
the
>KMDF use them for?
>
>

Encapsulation and polymorphism, I imagine. Vtables are the magic that
leads to interfaces and COM, and prograrmming by interface can be very
productive.


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


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Gosh - the exact solution we have used. We must be fools :wink:

“Doron Holan” wrote in message
news:xxxxx@ntdev…
1) We don’t use C++ EH
2) All calls to new() are checked for NULL. Since we wrote the
operator new(), we know it doesn’t throw
3) if the object itself needs to allocate more memory then just itself,
it does not do it in its ctor(). Rather, the object will have an
NTSTATUS Initialize(…) call in which the caller must call and check
the return value on. This is codified in our style guidelines doc and
must be followed in all of our code ;).

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J. Clarke
Sent: Thursday, April 27, 2006 2:28 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Placement new operator in a driver

Doron

Just to be curious what has been your approach to resoutce allocation
failure? Typical in C++ (and otehr o-o) is that constructor which fails
due
to resource allocation failure throws exception and the exception is
caught
and ‘handled’ for some value of ‘handled’. Now of course in kernel we
have
no C++ exceptions. First case is the object itself cannot be allocated;
simple case because ctor can return null. Second case is allocation of
the
object succeeds but ctor performs secondary allocations which fail; not
so
simple case.

Cheers
Lyndon

“Doron Holan” wrote in message
news:xxxxx@ntdev…
Vtables == virtual functions. We don’t do COM style pure abstract
interfaces, but we have a root object (FxObject) that is the basis for
all other KMDF objects. It has the std AddRef/Release/QI on it plus a
couple of other virtuals. Almost all of KMDF is pure function call that
is not virtual, there is only one object which uses virtual functions
for its heavy lifting.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, April 27, 2006 1:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Bruno van Dooren wrote:

>“Doron Holan” wrote in message
>news:xxxxx@ntdev…
>
>
>>Borrow? You surely jest ;). Design patterns are patterns for a
reason,
>>they are useful. Yes, the underlying implementation of KMDF is
written in
>>C++, but under some very strict rules. No references, no templates,
no
>>overloaded operators. Basically, we use C++ for vtables and vtables
only.
>>
>>
>
>Out of curiosity: what is so special about using vtables, and what does
the
>KMDF use them for?
>
>

Encapsulation and polymorphism, I imagine. Vtables are the magic that
leads to interfaces and COM, and prograrmming by interface can be very
productive.


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


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Great minds think alike :wink:

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J. Clarke
Sent: Thursday, April 27, 2006 3:16 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Placement new operator in a driver

Gosh - the exact solution we have used. We must be fools :wink:

“Doron Holan” wrote in message
news:xxxxx@ntdev…
1) We don’t use C++ EH
2) All calls to new() are checked for NULL. Since we wrote the
operator new(), we know it doesn’t throw
3) if the object itself needs to allocate more memory then just itself,
it does not do it in its ctor(). Rather, the object will have an
NTSTATUS Initialize(…) call in which the caller must call and check
the return value on. This is codified in our style guidelines doc and
must be followed in all of our code ;).

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J. Clarke
Sent: Thursday, April 27, 2006 2:28 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Placement new operator in a driver

Doron

Just to be curious what has been your approach to resoutce allocation
failure? Typical in C++ (and otehr o-o) is that constructor which fails
due
to resource allocation failure throws exception and the exception is
caught
and ‘handled’ for some value of ‘handled’. Now of course in kernel we
have
no C++ exceptions. First case is the object itself cannot be allocated;
simple case because ctor can return null. Second case is allocation of
the
object succeeds but ctor performs secondary allocations which fail; not
so
simple case.

Cheers
Lyndon

“Doron Holan” wrote in message
news:xxxxx@ntdev…
Vtables == virtual functions. We don’t do COM style pure abstract
interfaces, but we have a root object (FxObject) that is the basis for
all other KMDF objects. It has the std AddRef/Release/QI on it plus a
couple of other virtuals. Almost all of KMDF is pure function call that
is not virtual, there is only one object which uses virtual functions
for its heavy lifting.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, April 27, 2006 1:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Placement new operator in a driver

Bruno van Dooren wrote:

>“Doron Holan” wrote in message
>news:xxxxx@ntdev…
>
>
>>Borrow? You surely jest ;). Design patterns are patterns for a
reason,
>>they are useful. Yes, the underlying implementation of KMDF is
written in
>>C++, but under some very strict rules. No references, no templates,
no
>>overloaded operators. Basically, we use C++ for vtables and vtables
only.
>>
>>
>
>Out of curiosity: what is so special about using vtables, and what does
the
>KMDF use them for?
>
>

Encapsulation and polymorphism, I imagine. Vtables are the magic that
leads to interfaces and COM, and prograrmming by interface can be very
productive.


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


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer