Category Archives: C++

基于windows线程的并行前缀求和

#include #include #include #include #define NUM_THREADS 4 int N = 10000, *A; int intTotals[NUM_THREADS], outTotals[NUM_THREADS]; HANDLE doneStep1[NUM_THREADS]; HANDLE doneStep2; unsigned __stdcall prefixScan(LPVOID pArg) { if(NULL != pArg) { int tNum = *((int*)pArg); int start, end, i; int lPrefixTotal; free(pArg); pArg … Continue reading

Leave a Comment

Filed under C++, 技术

基于windows线程的并行线性查找

#include #include #include #include typedef struct{ int * A; int num; int key; int threadID; } sParam; bool Done = FALSE; #define NUM_THREADS 4 void linearSearch(int * A, int s, int e, int key, DWORD *position) { int i; for … Continue reading

Leave a Comment

Filed under C++, 技术

二进制文件二分查找算法

package com.xxx.xxx.query.version2; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.xxx.xxx.decode.MetaData; import com.xxx.xxx.utils.DateFormatUtil; public abstract class DataReader { protected static Log log = LogFactory.getLog(DataReader.class); protected static final int BUF_SIZE … Continue reading

Leave a Comment

Filed under C++, 技术

the art of c++第一章垃圾回收器iterator dereferencable错误解决方法

昨天看《the art of cpp》的时候,第二章垃圾回收器的sample代码 gc.h 在执行垃圾回收函数的时候 总是报iterator dereferencable的错误。 今天调试了一下,发现书上的源代码中 for(p = gclist.begin(); p != gclist.end(); p++) { … // Remove unused entry from gclist. gclist.remove (*p); … } 查了一下stl的reference,发现是的问题list 的remove 方法使用不当导致的iterator dereferencable 执行报错; 改为 for(p = gclist.begin(); p != gclist.end(); … Continue reading

3 Comments

Filed under C++, 技术

指针携带额外信息

我们有这样两个方法 PostQueuedCompletionStatus 和 GetQueuedCompletionStatus : BOOL PostQueuedCompletionStatus( HANDLE CompletionPort, // handle to an I/O completion port DWORD dwNumberOfBytesTransferred, // value to return via // GetQueuedCompletionStatus’ // lpNumberOfBytesTranferred DWORD dwCompletionKey, // value to return via // GetQueuedCompletionStatus’ // lpCompletionKey LPOVERLAPPED lpOverlapped … Continue reading

Leave a Comment

Filed under C++, 技术

C++编译器自动生成的基本函数

1 编译器自动生成的基本函数 C++编译器会在开发人员没有声明下列函数的时候,声明编译器自己的版本。 class Empty{} 等效于下面的声明 class Empty{ public: Empty(); //缺省构造函数 Empty(const Empty& rhs); //拷贝构造函数 ~Empty(); //析构函数 Empty & operator=(const Empty& rhs); //赋值运算符 Empty & operator&(); //取址运算符 const Empty * operator&() const; } 下面是编译器的参考实现 inline Empty::Empty() {} inline Empty::~Empty() {} … Continue reading

2 Comments

Filed under C++, 技术

C++ virtual应用的约束

virtual不正确使用会破坏数据的完整性(初始化完整性和释放完整性)。 delete或者free的时候需要指定类型,否则会造成部分资源未能被成功释放。 析构函数中不要调用虚函数,因为不会调用派生类对应的虚函数实现。 派生类的析构函数必须声明为virtual,否则可能不会调用派生类的析构函数。 C++标准规定:当通过基类的指针去删除派生类的对象,而基类又没有析构函数的时候,结果是不可确定的。 类对象实例含有虚函数,会导致对象实例的体积增加,因为持有一个指向虚函数表的指针。

Leave a Comment

Filed under C++, 技术