您正在查看 "程序代码" 分类下的文章 2011-09-13 16:07 用户级别的cpu绑定
绑定线程或进程函数:sched_setaffinity和pthread_setaffinity_np,pthread_setaffinity_np需要NPTL-version的pthread library。
sched_setaffinity example:
#include <stdio.h> #include <math.h> #include <sched.h> double waste_time(long n) { double res = 0; long i = 0; while(i <n * 200000) { i++; |
2008-11-14 12:00 /* 编译通过环境,Windows XP sp2,Windows 2003 server SDK,VC++6.0 sp5. */
/************************************************************************
* File: UDP group broadcast header file
* Author: WenXiaoyong,Wen_kernel@163.com
* Copyright: (C) WenXiaoyong,2007
* |
2008-11-13 13:33
VC中的socket通讯例程(UDP协议)
UDP的服务器端:(UdpSrv.cpp)
#include "Winsock2.h"
#include "stdio.h"
void main()
{
//初始化socket库
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
return;
}
if ( LOBYTE( wsaData.wVersion ) != 1 |
2008-08-12 15:52 Linux下创建静态、动态库
源码
-----------a.cpp---------------
#include <cstdio>
int a(int i)
{
std::printf("in a(int a) %d\n", i);
return 0;
}
-----------b.cpp----------------
#include <iostream>
int b(char *s)
{
std::cout<<"in int b(char *s): "<<s< |
2008-08-12 11:59 lib与DLL[转]
从这一章起,我讲述的内容将特定于windows平台。其实这篇文章也可看作是我在windows下的开发经验总结,因为以后我决定转unix了。
前面有一章说编译与链接的,说得很简略,其实应该放到这一章一块儿来说的。许多单讲C++的书其实都过于学院派,对于真实的工作环境,上百个源文件怎么结合起来,几乎没有提及。我引导读者一步步看看lib与DLL是怎么回事。
一个最简单的C++程序,只需要一个源文件,这个源文件包含了如下语句
int main(){return 0;}
自然,这个程序什么 |
2008-08-06 15:07 文件名: get_ipmac.c
代码:
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
#define MAXINTERFACES 16
int main(int argc, char **argv)
{
register int fd, interface, retn = 0;
|
2008-08-06 14:06
linux 进程间通讯
进程通讯是unix中很重要的知识。
产生一个新的进程主要有以下3种方法:
1,fork调用;
2,System调用;
3,Exec调用;
我们常说的进程通讯编程主要有以下3种方法:
1,Message queue队列编程;
2,Tcp/IP socket编程;
3,共享内存编程;
一、进程调用
1,产生进程Fork调用例子:
fork()
功能:创建一个新的进程.
语法:#include <unistd.h |
2008-06-17 17:49 /**
* Hash算法大全<br>
* 推荐使用FNV1算法
* @algorithm None
* @author Goodzzp 2006-11-20
* @lastEdit Goodzzp 2006-11-20
* @editDetail Create
*/
public class HashAlgorithms
{
/**
* 加法hash
* @param key 字符串
* @param prime 一个质数
* @return hash结果
*/
public static int additiveHash(String key, int prime)
{
int hash, i;
for (hash = key.length(), i = 0; i < key.length(); i++)
|
2008-06-03 13:51 #include <windows.h>
#include <stdio.h>
#include <vfw.h>
#pragma comment(lib,"vfw32.lib")
HWND ghWndCap ; //捕获窗的句柄
CAPDRIVERCAPS gCapDriverCaps ; //视频驱动器的能力
CAPSTATUS gCapStatus ; //捕获窗的状 |
2008-04-09 14:27 CListCtrl m_list;
解决CListCtrl刷新闪烁:
m_list->SetRedraw(FALSE) ;
|
| | |