God's in his heaven.
All's right with the world.

0%

各种 printf 函数采用格式字符串和可选参数,并生成用于输出的格式化的字符序列。 格式字符串包含零个或多个指令,这些指令是用于输出的文本字符或描述如何在输出中设置参数格式的已编码的转换规范。 本主题介绍用于对格式字符串中的转换规范进行编码的语法。 有关这些函数的列表,请参阅流 I/O

一个转换规范由以下形式的可选和必需字段组成:

%[标志][宽度][.精度][大小]类型

转换规范的每个字段都是一个用于指示特定的格式选项或转换说明符的字符或数字。 必填的类型字段指定要应用于参数的转换类型。 可选的标志、宽度和精度字段控制格式的其他方面(如前导空格或前导零、对齐方式和显示的精度)。 大小字段指定使用和转换的参数的大小。

一个基本的转换规范仅包含百分号和一个类型字符。 例如,%s 指定一个字符串转换。 若要打印百分号字符,请使用 %%。 如果百分号后跟一个没有任何意义的字符作为格式字段,则将调用无效的参数处理程序。 有关详细信息,请参阅参数验证

阅读全文 »

Ruediger Asche
Microsoft Developer Network Technology Group

Created: July 15, 1993

Abstract

This article discusses objects and handles under Microsoft® Windows™ version 3.1 and Windows NT™. The terms objects and handles have different meanings in each operating system and imply a variety of relationships between objects and their corresponding handles. This article elaborates on the differences between the way components of Windows NT treat objects as opposed to the way Windows 3.1 treats them, with particular emphasis on shareability issues.

阅读全文 »

Randy Kath
Microsoft Developer Network Technology Group

Created: January 20, 1993

Abstract

Determining which function or set of functions to use for managing memory in your application is difficult without a solid understanding of how each group of functions works and the overall impact they each have on the operating system. In an effort to simplify these decisions, this technical article focuses on the virtual memory management functions: which ones are available, how they are used, and how their use affects the operating system. The following topics are discussed in this article:

  • Reserving, committing, and freeing virtual memory
  • Changing protection on pages of virtual memory
  • Locking pages of virtual memory
  • Querying a process’s virtual memory

A sample application called ProcessWalker accompanies this technical article on the Microsoft Developer Network CD. This sample application is useful for exploring the virtual address space of a process. It also employs the use of virtual memory functions for implementing a linked list structure.

阅读全文 »

Randy KathMicrosoft Developer Network Technology Group

Created: February 9, 1993

Abstract

Determining which function or set of functions to use for managing memory in your application is difficult without a solid understanding of how each group of functions works and the overall impact they each have on the operating system. In an effort to simplify these decisions, this technical article focuses on the use of the memory-mapped file functions in Windows: the functions that are available, the way they are used, and the impact their use has on operating system resources. The following topics are discussed in this article:

  • Introduction to managing memory in Windows operating systems
  • What are memory-mapped files?
  • How are memory-mapped files implemented?
  • Sharing memory with memory-mapped files
  • Using memory-mapped file functions

In addition to this technical article, a sample application called ProcessWalker is included on the Microsoft Developer Network CD. This sample application is useful for exploring the behavior of memory-mapped files in a process, and it provides several useful implementation examples.

阅读全文 »

Randy Kath
Microsoft Developer Network Technology Group

Created: April 3, 1993

Abstract

Determining which function or set of functions to use for managing memory in your application is difficult without a solid understanding of how each group of functions works and the overall impact they each have on the operating system. In an effort to simplify these decisions, this technical article focuses on the use of heaps in Windows: the functions that are available, the way they are used, and the impact their use has on operating system resources. The following topics are discussed:

  • The purpose of heaps
  • General heap behavior
  • The two types of heaps
  • Global and local memory functions
  • Heap memory functions
  • Overhead on heap memory allocations
  • Summary and recommendations

In addition to this technical article, a sample application called ProcessWalker is included on the Microsoft Developer Network CD. This sample application explores the behavior of heap memory functions in a process, and it provides several useful implementation examples.

阅读全文 »

Murali R. Krishnan
Microsoft Corporation

February 1999

Summary: Discusses common heap performance problems and how to protect against them. (9 printed pages)

Introduction

Are you a happy-go-lucky user of dynamically allocated C/C++ objects? Do you use Automation extensively for communicating back and forth between modules? Is it possible that your program is slow because of heap allocation? You are not alone. Almost all projects run into heap issues sooner or later. The common tendency is to say, “It’s the heap that’s slow and my code is really good.” Well, that is partially right. It pays to understand more about heap, its usage, and what can happen.

阅读全文 »

可执行文件格式综述

相对于其它文件类型,可执行文件可能是一个操作系统中最重要的文件类型,因为它们是完成操作的真正执行者。可执行文件的大小、运行速度、资源占用情况以及可扩展性、可移植性等与文件格式的定义和文件加载过程紧密相关。研究可执行文件的格式对编写高性能程序和一些黑客技术的运用都是非常有意义的。

不管何种可执行文件格式,一些基本的要素是必须的,显而易见的,文件中应包含代码和数据。因为文件可能引用外部文件定义的符号(变量和函数),因此重定位信息和符号信息也是需要的。一些辅助信息是可选的,如调试信息、硬件信息等。基本上任意一种可执行文件格式都是按区间保存上述信息,称为段(Segment)或节(Section)。不同的文件格式中段和节的含义可能有细微区别,但根据上下文关系可以很清楚的理解,这不是关键问题。最后,可执行文件通常都有一个文件头部以描述本文件的总体结构。

相对可执行文件有三个重要的概念:编译(compile)、连接(link,也可称为链接、联接)、加载(load)。源程序文件被编译成目标文件,多个目标文件被连接成一个最终的可执行文件,可执行文件被加载到内存中运行。因为本文重点是讨论可执行文件格式,因此加载过程也相对重点讨论。下面是LINUX平台下ELF文件加载过程的一个简单描述。

阅读全文 »

Python的初学者(以及很多熟练工)相信都遇到过下面的运行时错误信息:

UnicodeDecodeError: ‘ASCII’ codec can’t decode byte 0xe4 in position 0: ordinal not in range(128)

然后百度一下发现说明这个问题的网页有一大把,基本无非是下面两种解决方案:

  1. 在Python文件的开头加一句#coding=utf-8
  2. 在代码中加入:
1
2
3
import sys
reload(sys)
sys.setdefaultencoding('utf8')

一般大家的做法是把两者都加上,然后问题一般也会得到解决。但很少有人会去深究过Python会什么会产生这样的编码问题,以及为什么通过加上面的代码可以解决这个问题。作为一个合格的程序员,遇到这种问题就应该追根究底,否则就只是以码谋生的码畜了 :)

阅读全文 »

一、设计模式的分类

总体来说设计模式分为三大类:

  • 创建型模式,共五种:工厂方法模式、抽象工厂模式、单例模式、建造者模式、原型模式。
  • 结构型模式,共七种:适配器模式、装饰器模式、代理模式、外观模式、桥接模式、组合模式、享元模式。
  • 行为型模式,共十一种:策略模式、模板方法模式、观察者模式、迭代子模式、责任链模式、命令模式、备忘录模式、状态模式、访问者模式、中介者模式、解释器模式。

其实还有两类:并发型模式和线程池模式。用一个图片来整体描述一下:

阅读全文 »