我的服务需要一个 cfg 文件,在容器开始运行之前需要对其进行更改。所以不适合将cfg打包成docker镜像。我需要从集群复制到容器,然后容器中的服务启动并读取这个配置文件。
我怎样才能做到这一点?
我有代码
#include <stdlib.h>
void *gg = malloc(55);
int main(int argc, char **argv)
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
gcc无法编译,但g ++可以工作。
因此,我只想确保在执行main之前发生malloc调用。
当我打开2人时,我得到了以下信息:
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);
int openat(int dirfd, const char *pathname, int flags);
int openat(int dirfd, const char *pathname, int flags, mode_t mode);
Run Code Online (Sandbox Code Playgroud)
这非常类似于函数重载。但是据说C根本不支持函数重载。那么,这里的魔力是什么?
考虑下面的例子
void func(int i){
if(i) {
int arr[2048] = {0};
//Doing something related to arr;
} else {
//Doing something
}
}
Run Code Online (Sandbox Code Playgroud)
我在if块中有一个大数组声明。该数组的初始化应花费一些时间。我的问题是:如果i == 0,该数组是否将全部初始化?
这是一个程序:
#include <cstring>
#include <iostream>
#include <string>
std::string fun(){
return "this is a string";
}
int main(){
const char *str = fun().c_str();
if(strcmp(str, "this is a string1") == 0){
std::cout << "ok" << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
当我用 AddressSanitizer 编译时,我得到:
=================================================================
==1841==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000000010 at pc 0x7ffff7658c18 bp 0x7fffffffd800 sp 0x7fffffffcfa8
READ of size 1 at 0x603000000010 thread T0
#0 0x7ffff7658c17 (/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libasan.so.6+0x8cc17)
#1 0x555555556500 in main /home/pqy/src/json/include/t.cpp:9
#2 0x7ffff7073ed9 in __libc_start_main ../csu/libc-start.c:314
#3 0x5555555561c9 in _start (/home/pqy/src/json/include/tt+0x21c9)
0x603000000010 …Run Code Online (Sandbox Code Playgroud)