64,649
社区成员
发帖
与我相关
我的任务
分享
CharSampleDevice * pDevice = new (
NULL,
FILE_DEVICE_UNKNOWN,
NULL,
0,
DO_DIRECT_IO
)//没有分号
CharSampleDevice(Pdo, m_Unit);
//其中
new (
NULL,
FILE_DEVICE_UNKNOWN,
NULL,
0,
DO_DIRECT_IO
)
//这种结构是CharSampleDevice 的基类kDevice的构造形式
/*
Create the device object. Note that we used a form of "placement" new,
that is a member operator of KDevice.
This form will use storage
allocated by the system in the device object's device to store our
class instance.
*/
// spec1_the_operator_new_function1.cpp
#include <malloc.h>
#include <memory.h>
class Blanks
{
public:
Blanks(){}
void *operator new( size_t stAllocateBlock, char chInit );
};
void *Blanks::operator new( size_t stAllocateBlock, char chInit )
{
void *pvTemp = malloc( stAllocateBlock );
if( pvTemp != 0 )
memset( pvTemp, chInit, stAllocateBlock );
return pvTemp;
}
// For discrete objects of type Blanks, the global operator new function
// is hidden. Therefore, the following code allocates an object of type
// Blanks and initializes it to 0xa5
int main()
{
Blanks *a5 = new(0xa5) Blanks;
return a5 != 0;
}
Blanks *SomeBlanks = new Blanks;
/*
Create the device object. Note that we used a form of "placement" new,that is a member operator of KDevice. This form will use storage allocated by the system in the device object's device to store our class instance.
*/
// spec1_the_operator_new_function1.cpp
#include <malloc.h>
#include <memory.h>
class Blanks
{
public:
Blanks(){}
void *operator new( size_t stAllocateBlock, char chInit );
};
void *Blanks::operator new( size_t stAllocateBlock, char chInit )
{
void *pvTemp = malloc( stAllocateBlock );
if( pvTemp != 0 )
memset( pvTemp, chInit, stAllocateBlock );
return pvTemp;
}
// For discrete objects of type Blanks, the global operator new function
// is hidden. Therefore, the following code allocates an object of type
// Blanks and initializes it to 0xa5
int main()
{
Blanks *a5 = new(0xa5) Blanks;
return a5 != 0;
}