阅读一些内核代码.
我无法理解这条线的含义
*(void **) &(int[2]){0,PAGE_SIZE};
Run Code Online (Sandbox Code Playgroud)
更重要的是,这意味着什么
{0,PAGE_SIZE}
Run Code Online (Sandbox Code Playgroud)
对我而言,它看起来不像是逗号的函数.
这段代码可能会发生什么?我不明白这里的间接性.
它是函数还是演员?支架部分是什么意思?似乎对我如此复杂,但绝对有意义.
阅读有关缓存优化的文章(与循环中的缓存行关联..)
问题与此上下文有关:1024个整数数组.
大小:cpu cache 64k,缓存行32bytes,整数size:4 bytes.
英特尔核心2二重奏
根据我的cpu,8个整数适合缓存行.
[0,1,2,3,4,5,6,7,8,9,10,...,1023]
^
If I want to access 4 and go downward, 3,2,1 and 0 will be loaded already. 5,6,7 are loaded uselessly.
[0,1,2,3,4,5,6,7,8,..,1023]
^
If I want to access 7 and go downward, all the next elements will be in cache already. if I want to go upward, according to my cpu I will have to load another cache line immediatly after the arr[7] read.
Run Code Online (Sandbox Code Playgroud)
我对么 ?
但是什么告诉我,arr [4]不在一个会导致缓存行加载的地址而不是arr …
Linux 64. AT&T.
GCC 4.8.2(-O3 -march = native)
左手下方的x86_64 abi,在第21页打开.
为了明确意图,这里有一个想法:
int32_t res[] = {0,0,0,0};
int32_t primo[] = {5,8,50,150};
for (int32_t x = 0; x < 4; ++x) {
res[x] = primo[x];
}
printf("%d %d %d %d\n", res[0], res[1], res[2], res[3]);
Run Code Online (Sandbox Code Playgroud)
检测到错误:
Error: `(%rsp,%esi,4)' is not a valid base/index expression
Run Code Online (Sandbox Code Playgroud)
代码 :
int32_t res[] = {0,0,0,0};
int32_t primo[] = {5,8,50,150};
int32_t counter = 0;
__asm__ volatile(
"start_loop:\n\t"
"movl (%1,%2,4), (%0,%2,4)\n\t"
"addl $1, %2\n\t"
"cmp $4, %2\n\t"
"jne …
Run Code Online (Sandbox Code Playgroud) 我是一个自学者,今天我的第一个套接字用c代码工作.高兴.
假设我们有sfd
一个套接字文件描述符.
执行此代码时:
flags = fcntl (sfd, F_GETFL, 0);
printf("FD MODE 1 - %d\n",fcntl(sfd,F_GETFL));
flags |= O_NONBLOCK;
s = fcntl (sfd, F_SETFL, flags);
printf("FD MODE 2 - %d\n",fcntl(sfd,F_GETFL));
Run Code Online (Sandbox Code Playgroud)
它输出:
2
2050
Run Code Online (Sandbox Code Playgroud)
但是我的fcntl-linux.h说:
...
/* open/fcntl. */
#define O_ACCMODE 0003
#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02
#ifndef O_CREAT
# define O_CREAT 0100 /* Not fcntl. */
#endif
#ifndef O_EXCL
# define O_EXCL 0200 /* Not fcntl. */
#endif
#ifndef O_NOCTTY
# define O_NOCTTY 0400 …
Run Code Online (Sandbox Code Playgroud) 试图了解lto(链接时间编译)的工作原理
我有这些文件:
julia.h:
#ifndef JULIA_H
#define JULIA_H
#include <stdio.h>
int julian();
#endif // JULIA_H
Run Code Online (Sandbox Code Playgroud)
julia.c:
#include "julia.h"
int julian()
{
printf("Hello Worldu!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译为共享库如下:gcc -O3 -fPIC -shared julia.c -o libjulia.so -L $ PWD -I $ PWD -flto
和我的主要计划:
main.c中
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "julia.h"
int main()
{
julian();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译:GCC -O3 main.c中-I /路径/到/ INC -L /路径/到/ lib中-Wl,-rpath = /路径/到/ lib中-ljulia -flto
它编制罚款.
所以,这是一个hello world程序,但我是否正确使用LTO?是否只需要优化连接?
谢谢
Debian 64bits尝试将int(例如233)写入文件并使其文本打印为"é".
我无法理解如何编写一个utf8等效字符,例如"é"或任何比char类型更宽的UTF-8字符.该文件应该是人类可读的,以通过网络发送.
我的目标是将int写入文件并获得其utf8等效项.
我不知道我在做什么.
FILE * dd = fopen("/myfile.txt","w");
fprintf(dd, "%s", 233); /* The file should print "é" */
fclose(dd);
Run Code Online (Sandbox Code Playgroud)
谢谢
更新:
根据Biffen的评论,这里是写"E9"("é"的十六进制值)的另一个代码片段;
int p = 233;
char r[5];
sprintf(r,"%x",p);
printf("%s\n",r);
fwrite(r,1,strlen(r),dd);
fclose(dd);
Run Code Online (Sandbox Code Playgroud)
如何将其转换为"é"?
UFILE * dd = u_fopen("/myfile.txt","wb", NULL, NULL);
UChar32 c = 233;
u_fputc(c,dd);
u_fclose(dd);
Run Code Online (Sandbox Code Playgroud) Is there a way to get the occupied memory size in bytes of BigInt numbers?
let a = BigInt(99999n)
console.log(a.length) // yield undefined
Run Code Online (Sandbox Code Playgroud)
Thanks
是否可以通过ac程序或终端(linux)中的地址获取文件?我知道这对我来说听起来很奇怪,但我只是在尝试.
例如,替换
FILE * f = fopen("myfile.txt","r")
Run Code Online (Sandbox Code Playgroud)
通过绝对令人惊叹的东西
int fd = open(&0x545f6f5,"r")
Run Code Online (Sandbox Code Playgroud)
或echo&0x545f6f5会抓取相关文件的一部分(需要一个长度,所以更像echo和0x545f6f5 20来读取地址旁边的20个字节)?
我知道mmap,但同样,我的问题更像是实验.
那么,整体情况是:可以使用地址(理想情况下是长度)访问linux文件系统上文件的任何部分吗?
说我的分区ID/dev/sda1,我想访问带有地址而不是名称的原始内存值(可读或不可读).如果我寻找地址&0x545f6f5并且恰好是偏移量为64的myfile.txt,我会读取该位置的字节.我希望它能让它更清晰:)
我使用了很多按位操作,但我甚至不知道它们是如何在最低级别实现的.
我想看看intel/amd devs如何实现这些操作.不要在我的代码中替换它们,这将是愚蠢的..但是要更广泛地了解正在发生的事情.
我试图找到一些信息,但大多数时候,人们会询问它的使用或用其他按位操作替换它,这不是这里的情况.
它是否在32位的汇编(sse)中进行基本迭代并进行比较?
是否有一些技巧可以加快速度?
谢谢