我一直在Google上搜索一种在mac os下进行原始(有时称为直接)i/o的方法.操作系统页面缓存的原始i/o转动使应用程序可以更直接地访问磁盘.这很有用,因为我使用的某些文件结构使用LRU页面替换效率不高.实现我们需要的页面替换算法是相当直接的,但首先我们需要关闭os x默认缓冲.我们已经在打开文件时使用O_DIRECT标志在linux下完成了这个.有没有人知道如何在mac os下关闭页面缓冲?
干杯蒂姆
我正在使用CreateFileMapping和MapViewOfFile函数将文件映射到内存中.在某一点之后,我调用VirtualProtect将其保护从只读更改为读写.此调用失败,GetLastError提供ERROR_INVALID_PARAMETER.
这是我的代码的简化版本,用于演示此问题.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main() {
HANDLE fd, md;
char *addr;
DWORD old;
BOOL ok;
fd = CreateFile("filename", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
md = CreateFileMapping(fd, NULL, PAGE_READWRITE, 0, 100, NULL);
addr = MapViewOfFile(md, FILE_MAP_READ, 0, 0, 100);
ok = VirtualProtect(addr, 100, PAGE_READWRITE, &old);
if (!ok) {
// we fall into this if block
DWORD err = GetLastError();
// this outputs "error protecting: 87"
printf("error protecting: %u\n", err);
return 1;
}
UnmapViewOfFile(addr);
CloseHandle(md);
CloseHandle(fd); …Run Code Online (Sandbox Code Playgroud) 制作容量小于长度的切片
package main
import fmt "fmt"
func main(){
type b []int
var k = make([]b, 10, 5)
fmt.Printf("%d\n",k[8])
}
尝试运行时会出现以下错误.
panic: runtime error: makeslice: cap out of range
runtime.panic+0x9e /go/src/pkg/runtime/proc.c:1060
runtime.panic(0x453b00, 0x30020390)
runtime.panicstring+0x94 /go/src/pkg/runtime/runtime.c:116
runtime.panicstring(0x4afd6c, 0x40d80c)
runtime.makeslice+0x70 /go/src/pkg/runtime/slice.c:24
runtime.makeslice(0x44302c, 0xa, 0x0, 0x5, 0x0, ...)
main.main+0x45 C:/GOEXCE~1/basics/DATATY~1/slice.go:8
main.main()
runtime.mainstart+0xf 386/asm.s:93
runtime.mainstart()
runtime.goexit /go/src/pkg/runtime/proc.c:178
runtime.goexit()
----- goroutine created by -----
_rt0_386+0xbf 386/asm.s:80
我的问题是容量能否小于长度?
如果'是'那么为什么会出现这个错误?
如果'不是为什么这是一个运行时错误,为什么不编译时?
我想在我的应用程序中添加一个swf文件的flash.是否有任何简单的方法以编程方式执行此操作.