由买买提看人间百态

topics

全部话题 - 话题: sizeof
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
w****x
发帖数: 2483
1
来自主题: JobHunting版 - 几道F家面试题
//serialize, deserialize vector
int serialize(vector& vec, char* str)
{
if (str == NULL)
return 0;
char* pWriter = str;
*((int*)pWriter) = vec.size();
pWriter += sizeof(int);
for (int i = 0; i < vec.size(); i++)
{
strcpy(pWriter, vec[i].c_str());
pWriter += 1 + strlen(pWriter);
}
return pWriter - str;
}
void deserialize(char* str, vector& vec)
{
if (NULL == str)
return;
int nSize = *((int*)str);
c... 阅读全帖
w****a
发帖数: 710
2
想起以前在国内面游戏公司的题。。。我写几个我遇到过的印象深刻的
1. sizeof(std::map) = ?
sizeof(std::vector) = ?
2. 给一段简单的函数调用代码,请写出Debug模式下的反汇编代码,参考IDE: vs2005。
3. 请尽可能多地写出win32下C++内存管理面对的问题和对应解决方案。
4. 朝某个轴转X度,请写出对应的3x3旋转矩阵。
5. 让你设计和开发一个UI库,你有什么规划。
6. 系列动画片喜羊羊与灰太狼中的羊村村长叫什么名字。
7. 一题用高中物理的动量守恒定律做的应用题。
9. 请画出Direct3D9的详细渲染管线流程。
大家喜欢做哪种题?算法题 还是我说的这些?
l*******b
发帖数: 2586
3
来自主题: JobHunting版 - 一道A家店面题求解
大家看看有没有bug, 初步试了两个好像是对的
#include
using namespace std;
bool gt (int a, int b) { return a > b; }
bool lt(int a, int b) { return a < b; }
bool eq(int a, int b) { return a == b; }
bool ge(int a, int b) { return a >= b; }
bool le(int a, int b) { return a <= b; }
int search(int A[], int N, int key, bool (*f) (int, int)) {
int dir = f(A[0], A[N-1]) ? -1 : 1; // direction of the search
int cur = (dir == 1) ? 0 : N - 1;
while(!f(A[cur], key)) {
cur += dir;
if(cur < 0... 阅读全帖
f*******t
发帖数: 7549
4
来自主题: JobHunting版 - F,G,M offer 及 面试经历
#include

using namespace std;

void printNumCount(int arr[], int n)
{
for (int i = 0; i < n; i++) {
int x = arr[i];
if (x <= 0)
continue;
else {
int y = arr[x-1];
if (y <= 0) {
arr[x-1]--;
arr[i] = 0;
} else {
arr[i] = y;
arr[x-1] = -1;
i--;
}
}
}
for (int i = 0; i < n; i++)
cout << "Count o... 阅读全帖
f*******t
发帖数: 7549
5
来自主题: JobHunting版 - F,G,M offer 及 面试经历
#include

using namespace std;

void printNumCount(int arr[], int n)
{
for (int i = 0; i < n; i++) {
int x = arr[i];
if (x <= 0)
continue;
else {
int y = arr[x-1];
if (y <= 0) {
arr[x-1]--;
arr[i] = 0;
} else {
arr[i] = y;
arr[x-1] = -1;
i--;
}
}
}
for (int i = 0; i < n; i++)
cout << "Count o... 阅读全帖
j*****y
发帖数: 1071
6
来自主题: JobHunting版 - 报个电面的面经和据信吧, 求安慰
void * mymalloc(int size, int align) // align is a power of 2
{
void * p = (void *)malloc(size + align - 1 + sizeof(void *));
void * p1 = (void *)((((int)p) + align -1 + sizeof(void *)) & (~(align
- 1)));
void **p2 = (void **)p1;
p2[-1] = p;
return p1;
}
void myfree(void *p)
{
void **p2 = (void **) p;
free(p2[-1]);
}
j*****y
发帖数: 1071
7
来自主题: JobHunting版 - 报个电面的面经和据信吧, 求安慰
void * mymalloc(int size, int align) // align is a power of 2
{
void * p = (void *)malloc(size + align - 1 + sizeof(void *));
void * p1 = (void *)((((int)p) + align -1 + sizeof(void *)) & (~(align
- 1)));
void **p2 = (void **)p1;
p2[-1] = p;
return p1;
}
void myfree(void *p)
{
void **p2 = (void **) p;
free(p2[-1]);
}
b******7
发帖数: 92
8
来自主题: JobHunting版 - Amazon面经
byte有几个bits,应该是sizeof(byte)*8
就如同int有几个bits,是sizeof(int)*8
r***e
发帖数: 29
9
来自主题: JobHunting版 - BBC 编程风格面试题,求指教
我的答案(C++):
#pragma once
#ifndef _ROMON_HEADER_
#define _ROMON_HEADER_
#include
#include
using namespace std;
const string ROMON_DIGIT[] = {"","I","II","III","IV","V","VI","VII","VIII","
IV"};
//ROMON 0-9
const int ROMON_SCALE[] = {10, 50, 100, 500, 1000};
const char ROMON_SCALE_REP[] = {'X', 'L', 'C', 'D', 'M'};
//ROMON scale
const int ROMON_MAX = 3999;
const int ROMON_MIN = 1;
// rewrite the interface
class RomanNumeralGenerator
{
public:
virtual string generator(int n... 阅读全帖
t*****h
发帖数: 137
10
来自主题: JobHunting版 - BBC 编程风格面试题,求指教
I haven't finished reading your code. But from the very beginning, you're
using namespace std.
My understanding is never using namespace std in the header, any other
classes use your class will have the namespace contamination.
#pragma once is also non standard.
修改
最后一行
static const int _scale = sizeof(ROMON_SCALE)/sizeof(int);
我们一般都把测试分开,这样可以用flag关掉测试,最后release的时候会比较小点。
e*******i
发帖数: 56
11
来自主题: JobHunting版 - 求教rotate matrix扩展的解法
Need to make base class destructor virtual. Here since A's destructor is
nonvirtual, "delete b" will call A's destructor. But b is actually pointing
to a B object. It will free memory of sizeof(A), not sizeof(B), thus crash.
i******a
发帖数: 11
12
来自主题: JobHunting版 - Qualcomm面经
个人背景是fresh cs PhD。面试挺顺利,感觉都不错,主要围绕简历上的项目讨论。但
不幸被拒。Hiring manager说 definitely impressed with your interview,但只有
一个职位。说是把我推荐给其他组了。 这个是客气话不? 这种还有戏么?Recruiter
电话里也说过我被推荐给其他组了,但是都快一个月了,也没消息。Recruiter也从不
回email。是不是还没有其他组表示感兴趣? Anyway, move on了。
1. Read code to say which c routine function it is. Interviewer want to see
how you understand a program.
00009 void *
00010 f1(register const void *p1, register const void *p2,
00011 register size_t n1, register size_t n2,
00012 int (*f2)(cons... 阅读全帖
i******a
发帖数: 11
13
来自主题: JobHunting版 - Qualcomm面经
个人背景是fresh cs PhD。面试挺顺利,感觉都不错,主要围绕简历上的项目讨论。但
不幸被拒。Hiring manager说 definitely impressed with your interview,但只有
一个职位。说是把我推荐给其他组了。 这个是客气话不? 这种还有戏么?Recruiter
电话里也说过我被推荐给其他组了,但是都快一个月了,也没消息。Recruiter也从不
回email。是不是还没有其他组表示感兴趣? Anyway, move on了。
1. Read code to say which c routine function it is. Interviewer want to see
how you understand a program.
00009 void *
00010 f1(register const void *p1, register const void *p2,
00011 register size_t n1, register size_t n2,
00012 int (*f2)(cons... 阅读全帖
g***9
发帖数: 159
14
来自主题: JobHunting版 - 问一道题(2)
也贴个完整代码,序列shift移位的方法,把前一半的正数和后一半的负数对调但各自
顺序不变,
这个记得是编程珠玑的里的貌似。。
#include
#include
#include
#include
using namespace std;
void MySortImpl(vector &v, int b, int e) {
if (b >= e) {
return;
}
int m = (b + e) / 2;
MySortImpl(v, b, m);
MySortImpl(v, m+1, e);
int i, j;
i = m+1;
while (i-1 >= b && v[i-1] > 0) i--;
j = m;
while (j+1 <= e && v[j+1] < 0) j++;
int len1 = m - i + 1;
int len2 = j - (m+1) + ... 阅读全帖
r*c
发帖数: 167
15
来自主题: JobHunting版 - 问一道题(6)
贴个pattern字符串有重复字符的解法, 是dek,cpp1等大牛的解法的扩展。
#include
#include
#include
#include
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
class MinWindowSolution
{
public:
struct TreeNode
{
TreeNode *parent;
int val;
vector children;
TreeNode(int i, TreeNode *p) : val(i), parent(p){}
};
void FindMinWindow_Tree(const vector& input , const vector&
query , int& nStart,... 阅读全帖
g***9
发帖数: 159
16
来自主题: JobHunting版 - 问一道题(7)
遵照大牛的思路写了个实现:
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int getMaxEvenSeq(vector &v) {
int n = v.size();
if (n < 2) {
return 0;
}
vector pos(2*n+1, -1);
int zeros, ones;
int i, t, diff, index, dis, ans;
zeros = ones = 0;
ans = 0;
for (i = 0; i < n; i++) {
t = v[i];
if (t == 0) {
... 阅读全帖
p****o
发帖数: 46
17
oj 在{0, 1}测试的结果是{{1}, {0,1}, {1,0}}
但我自己运行打印出来是{{0,1}, {1,0}}
请大伙帮忙看看。
代码如下
#include "stdio.h"
#include
using namespace std;
class Solution {
public:
vector > permute(vector &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector v(0);
doPermute(v, num);
return vv;
}

void doPermute(vector &v, vector &num) {
if(num.empty()) {
vv.push_back(v); ... 阅读全帖
l******s
发帖数: 13
18
来自主题: JobHunting版 - 求教计算机安全问题
考虑下面的代码,在Linux上运行:
// soc is a socket
if ( read(soc, buf, sizeof(buf)) > 0 )
{
snprintf(cmd, sizeof(cmd), "rm -f "%s"", buf);
system(cmd);
}
你会如何写script 检查证明这个漏洞存在,并没有任何破坏原有系统, 在这样一种方
式下,最终用户不会认为这是 false alarm?
m**********g
发帖数: 153
19
来自主题: JobHunting版 - A家onsite, 求bless
这个验证通过:
#include
#include
#include
using namespace std;
void rotate(int a[], int k, int n) {
int i=0;
k = k%n;
for (; i+k if (n%k == 0) return;
rotate(&a[i], k - n%k, k);
}
int main()
{
int i;
int a[]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotate(a, 5, 12);
for(i=0; i printf( "%d ", a[i]);
}
printf("n");
return 0;
... 阅读全帖
w********s
发帖数: 1570
20
来自主题: JobHunting版 - FB 面经
当然是0,O(n)复杂度
#include
int abs_diff(int a, int b)
{
if (a < b) return b - a;
return a - b;
}
int rotate_min_step(int k, int size)
{
int p = k + 1;
if (p < size - p) return p;
return size - p;
}
int rotation_distance(int* a, int size)
{
if (size == 1) return 0;
int max_diff = abs_diff(a[0], a[1]);
int max_pos = 0;
for (int i = 1; i < size; ++i)
{
int di = abs_diff(a[i], a[(i + 1) % size]);
if (di > max_diff)
{
max_diff = di;
max_pos = i;
}... 阅读全帖
l**********7
发帖数: 55
21
来自主题: JobHunting版 - 请教一道题
牛!
Follow your idea. Here are my two cents.
void sortbst(int *A, int n)
{
int k, h;
//compute height
for (h=1;;h++) {
if (1< }
//start the last left node with two leaves
//do inorder traverse the array
k=1<<(h-2)-1;
while(1)
{
printf(" %d ",A[2*k+1]);
printf(" %d ",A[k]);
printf(" %d ",A[2*k+2]);
if(2*k+2>=n-1) break;
printf(" %d ", A[k/2]);
k=k+1;
}
printf("n");
}
// a should be from a com... 阅读全帖
r****7
发帖数: 2282
22
来自主题: JobHunting版 - 请教一道G的电面题。。
Java里边默认是传引用吧
C++写了个,看了下和你的逻辑应该一样的,不过我觉得这个叫DFS是不是牵强了点儿。
。。
#include
#include
using namespace std;
int size;
void print(vector arr)
{
for (int i = 0; i < arr.size(); i++) {
printf("%c ", arr[i]);
}
printf("n");
}
void backtracking(vector arr, int len)
{
if (len == size) {
print(arr);
return;
}
int currLen = len;
len ++;
if (arr[currLen - 1] == '*') {
arr[currLen - 1] = '0';
backtracking(arr, len);
arr[currLe... 阅读全帖
j********8
发帖数: 10
23
来自主题: JobHunting版 - 版上看到的几道F家的题目
static int setBit(int input, int bit)
{
int mask = 1;
mask <<= bit;
return input |= mask;
}
// assumption all characters are lower case
static vector findSubStr(string source, vector chars)
{
vector result;
// first convert chars into an integer, where bit 0-25 correspond to
a-z, o(n)
int charsBits = 0;
for (int i = 0; i < chars.size(); i++)
{
int bit = chars[i] - 'a';
... 阅读全帖
w****k
发帖数: 755
24
来自主题: JobHunting版 - 问几个coding中的behavior question
感觉不同的面试官着眼点不一样,我想知道普遍的做法。
1. 要求写代码时,是先想解题思路,还是先问诸如数据size多大,考虑内存不够等等?
2. 先写代码还是先列出所有测试条件,比方说输入无效或者越界数据?我习惯于先写
代码在测试是否能处理所有情况,然后改改,这似乎给人印象不好?
3. 边写边说还是闷着头写?我习惯于前者,但好几次感觉面试官忙着自己的事情,觉
得我在烦他。
4. 出题前面试官介绍了一通后会问有没有问题,是说没有省点时间来做题呢,还是先
问一通以显示自己的兴趣呢?
5. 有没有必要把一个小模块独立成小函数?我以前习惯于这个,但后来发现许多大牛
都写一个函数就完了,很NB的样子,于是也这样了。
6. 可以使用global variable么?比方在C++里面写处理二维数组的函数的话,把数组
指针和大小做成global的话会容易很多,不然就要sizeof/sizeof一大串。当然写
global variable在实际工作中尽量得少用。
h*******t
发帖数: 2679
25
来自主题: JobHunting版 - google 电面
#include
#include
using namespace std;
char XOR(string s)
{
char result = 0;
for(int i = 0; i result ^= s[i];
return result;
}
int main()
{
char targetXOR = XOR("pto");
string dict[]={"hello", "world", "pot", "opt"};
char result = 0;
for (int i = 0; i {
result = XOR(dict[i]) ^ targetXOR;
if(!result)
cout << dict[i] < }
delete dict;
return 0;
}
x*******9
发帖数: 138
26
来自主题: JobHunting版 - 请教一道算法题
略暴力,Lintcode上的题。(没看错,是Lintcode,不是Leetcode)
class Solution {
public:
/**
* @param A: An integer array.
* @param target: An integer.
*/
int MinAdjustmentCost(vector A, int target) {
if (A.empty()) {
return 0;
}
int n = A.size();
int ptr = 0;
memset(dp, 0, sizeof(dp));

for (int i = 0; i < n; i++) {
int cur = A[i];
int next = ptr ^ 1;
memset(dp[next], INF, sizeof(dp[nex... 阅读全帖
H**********5
发帖数: 2012
27
来自主题: JobHunting版 - 感觉今天结结实实被烙印阴了
#include
#include
typedef struct node
{
int data;
struct node* next;
};
void printfList(struct node *head)
{
while(head!=NULL)
{
printf("%d-> ",head->data);
head=head->next;
}
printf("\n");
}
void pushAtBegin(struct node **head_ref,int data)
{
struct node *new_node=(struct node*)malloc(sizeof(struct node));
new_node->data=data;
new_node->next=*head_ref;
*head_ref=new_node;
}
void pushAtEnd(struct node **head_ref,i... 阅读全帖
x*******9
发帖数: 138
28
来自主题: JobHunting版 - 请教G家新题 continental divider
#include
#include
#include
#include
#include
#include
using namespace std;
#define input(x) cin >> x
#define print(x) cout << x << endl
const int SIZE = 512;
const int mx[] = {0, 1, 0, -1};
const int my[] = {-1, 0, 1, 0};
int n, sea_cnt;
char g[SIZE][SIZE];
int nr[SIZE][SIZE];
int cnc[SIZE][SIZE];
void find_sea(int y, int x) {
if (g[y][x] != '0') {
return;
}
nr[y][x] = sea_cnt;
for (int i = 0; i < 4; i++) {
... 阅读全帖
T******7
发帖数: 1419
29
#include
#include
// Matrix Ai has dimension p[i-1] x p[i] for i = 1..n
int MatrixChainOrder(int p[], int n)
{
/* For simplicity of the program, one extra row and one extra column are
allocated in m[][]. 0th row and 0th column of m[][] are not used */
int m[n][n];
int i, j, k, L, q;
/* m[i,j] = Minimum number of scalar multiplications needed to compute
the matrix A[i]A[i+1]...A[j] = A[i..j] where dimention of A[i] is
p[i-1] x p[i] */
/... 阅读全帖
c*******4
发帖数: 51
30
来自主题: JobHunting版 - 谷歌 On site 2015.5月面试
可能我没写清除或者你想复杂了,
直接从一开始扫,因为array sort过了,所以只要后面=前面的就开始记录就好了,
array长度你能知道,用vector是.size(),array的话 sizeof(A)/sizeof(A[0])然后比
较重复和N/4
n****5
发帖数: 81
31
来自主题: JobHunting版 - fb电面面经
用 C 写了一下,用的递归来处理商和余数。用的unsigned int所以假定输入小于1百万
X1百万
#include
#include
const char* tens[] = {"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "
Seventy", "Eighty", "Ninety"};
const char* lt20[] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten",
"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "
Sixteen", "Seventeen", "Eighteen", "Nineteen"};
void num2str(unsigned int num)
{
if (num == 0)
return;
el... 阅读全帖
f******n
发帖数: 198
32
来自主题: JobHunting版 - 老码农骂小码农的强文。 (转载)
He certainly has a point, but he's not completely correct. If hlen + sizeof(
struct frag_hdr) does not overflow, but hlen + sizeof(struct frag_hdr) + 8
does, his version will give a negative mtu result.
x****o
发帖数: 21566
33
【 以下文字转载自 Linux 讨论区 】
发信人: wjk302 (akui), 信区: Linux
标 题: 大家能帮我看一下下面的问题吗,不胜感激。
发信站: BBS 未名空间站 (Wed Feb 1 22:05:13 2012, 美东)
很冒昧的打扰大家。大家能帮我看一下下面的问题吗,不胜感激。
问题是这样的,在生产环境下
1、Suse的Linux有 /nfsmnt/work_pub/web 文件夹和 /nfsmnt/work_inwork/web
文件夹 ,它们都是NFS文件挂载
2、机器上有多个进程会读写/nfsmnt/work_pub/web 文件夹的内容
3、cron会周期性的 删除/nfsmnt/work_pub/web 文件夹下所有文件,并把/nfsmnt/
work_inwork/web 文件夹下的所有内容拷贝到前面那个文件夹中
这样,完全删除/nfsmnt/work_pub/web 文件夹下所有文件的时候就会有.nfs文件删除
不掉(上面的流程因为某些问题不方便改动)。
想咨询的问题是:我现在能不能修改一下fs/nfs/dir.c ... 阅读全帖
f******y
发帖数: 14
34
来自主题: BuildingWeb版 - how to upload a local file to web server?
下面是c语言的,
你不必仔细看,这是cgihtml的一部分,你在网上搜索cgihtml,
保证可以搞到全部代码,
其实上在文件是非常基本的功能,网上肯定有,找就是了
int parse_form_encoded(llist* entries)
{
long content_length;
entrytype entry;
node* window;
FILE *uploadfile;
char *uploadfname, *tempstr, *boundary;
char *buffer = (char *)malloc(sizeof(char) * BUFSIZ + 1);
char *prevbuf = (char *)malloc(sizeof(char) + BUFSIZ + 1);
short isfile,done,start;
int i,j;
int bytesread,prevbytesread;
int buffersize;
int numentries = 0;
#ifdef WINDOWS
setmode(f
g*********s
发帖数: 1782
35
【 以下文字转载自 Programming 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: Programming
标 题: STL map变量的实际memory usage估算
发信站: BBS 未名空间站 (Sat Apr 26 23:08:58 2008)
比如声明这样一个变量
using namespace std;
map *nameMap = new(map);
... // 在nameMap里插入了1000个(string, int) pair
现在需要估算这时heap的size增加了多少?
估算如下:
本身sizeof(map<...,...>)是48个字节。
一个string s的size是 sizeof(string) + s.size(),假定字符串长度都是8,则是16。
一个int是4字节。
这样至少是48+1000*(4+16)=2048 bytes。
但是map是用rb_tree实现,加上开销是多少呢?看了一下source code,不太确定是不
是算对了。
每个node包含c
a9
发帖数: 21638
36
我说说我的吧:
80口开的apache,允许connect到443
openvpn开443,侦听127.0.0.1
服务器端:
mode server
tls-server
ifconfig 172.19.0.1 255.255.0.0
ifconfig-pool 172.19.0.100 172.19.254.254 255.255.0.0
proto tcp-server
port 443
local 127.0.0.1
dev tap
comp-lzo
keepalive 15 60
verb 3
ca /etc/openvpn/ca.crt
dh /etc/openvpn/dh.pem
cert /etc/openvpn/tmobilewall.crt
key /etc/openvpn/tmobilewall.key
status-version 2
status status
tmp-dir /dev/shm
auth-user-pass-verify /etc/openvpn/tmobilewall_auth.php via-file
username-as-common-... 阅读全帖
r*******y
发帖数: 1081
37
来自主题: Linux版 - 看看这个 C 代码
#include
int f(double a[]){
return sizeof(a);
}
int main(void){

double a[100];
printf("%d %d\n", f(a), sizeof(a)));
}
为什么显示出来的是 4 800
而不是我想要的 800 800
有什么办法让函数的返回值是800吗?
谢谢
i*****f
发帖数: 578
38
来自主题: Linux版 - 看看这个 C 代码
simply put,
in f()'s argument, type is double *. sizeof(double*) is 4
in main(), type is double[100], sizeof(double[100]) is 800
i*****f
发帖数: 578
39
来自主题: Linux版 - 看看这个 C 代码
yes your code implements the sizeof opterator. but sizeof operator does not
solve lz's problem, which is determining array's size at *runtime* only
through a pointer to that array.
r*******y
发帖数: 1081
40
来自主题: Linux版 - 看看这个 C 代码
I think I get a better one now as I desired
#include
#include
#include
int f(double *a){
return malloc_usable_size(a) - sizeof(void *);
}
int main(void){
double *a= malloc(sizeof(double) * 100);
printf("%d \n", f(a));
}
Thanks.
d**d
发帖数: 389
41
【 以下文字转载自 Programming 讨论区 】
发信人: dxxd (东邪西毒), 信区: Programming
标 题: 请教一个linux下的POSIX timer的问题。
发信站: BBS 未名空间站 (Fri May 13 17:06:15 2011, 美东)
我用linux下面的POSIX timer, timer_create(),timer_settime(),
为什么在调用了timer_settime()以后,立马就有一个time-out callback? 然后再每过
5秒后有一个time out?
难道不是我调用timer_settime()以后,timer开始计时, 等到5秒以后再出现第一
time out callback 吗?
非常感谢!
代码如下:
#include
#include
#include
#include
#include
void
handle (sigval_t v)
{
tim... 阅读全帖
w****2
发帖数: 2
42
很冒昧的打扰大家。大家能帮我看一下下面的问题吗,不胜感激。
问题是这样的,在生产环境下
1、Suse的Linux有 /nfsmnt/work_pub/web 文件夹和 /nfsmnt/work_inwork/web
文件夹 ,它们都是NFS文件挂载
2、机器上有多个进程会读写/nfsmnt/work_pub/web 文件夹的内容
3、cron会周期性的 删除/nfsmnt/work_pub/web 文件夹下所有文件,并把/nfsmnt/
work_inwork/web 文件夹下的所有内容拷贝到前面那个文件夹中
这样,完全删除/nfsmnt/work_pub/web 文件夹下所有文件的时候就会有.nfs文件删除
不掉(上面的流程因为某些问题不方便改动)。
想咨询的问题是:我现在能不能修改一下fs/nfs/dir.c 中 nfs_sillyrename这个方法
,把所有.nfs文件生成到/nfsmnt/temp目录下,然后重新编译内核解决上面的问题?期
待大家的指点,先谢谢了。
下面是源代码
static int nfs_sillyrename(struct in... 阅读全帖
M**********n
发帖数: 432
43
来自主题: Linux版 - 这个程序有错莫
sizeof(bool) = 1
sizeof(int) = 4
i**p
发帖数: 902
44
【 以下文字转载自 Programming 讨论区 】
发信人: isup (No), 信区: Programming
标 题: 哪位用过tty_flip_buffer_push()?
发信站: BBS 未名空间站 (Sun Jun 15 17:43:46 2014, 美东)
I am trying to run tiny_tty in LDD3. When I use "cat /dev/ttty0" to read
from it, there is no output and the command is blocked.
Checking the trace, I notice both tty_insert_flip_char() and tty_flip_buffer
_push() are called. However, the data is not sent to the user by tty core.
Instead, it is sent back to the tiny_tty driver's tiny_write() callback
functio... 阅读全帖
z**********r
发帖数: 86
45
来自主题: Programming版 - size不固定的struct怎么定义呀?
我是这么用的(verified on Ubuntu):
typedef struct
{
// fixed length data
int len;
// any varying length data should be put below
// note, you must be used data[] instead of *data
// because data[] does't take extra space; *data takes four bytes for the
pointer
char data[];
}Array;
// for allocate
int len=10;
Array *x=(Array *)malloc(len*sizeof(char)+sizeof(Array));
x->len=10;
// access the varying length part
x->data[0]='c';
// for deallocate
free(x);
q*****g
发帖数: 1568
46
来自主题: Programming版 - 关于malloc/free和循环
假设说我用malloc分配了一些内存给变量v:
double * v = (double *) malloc ( 10 * sizeof(double));
现在开始一个循环,其中v每次的值都不一样,那么我是不是需要
在循环体内free之(当然这就意味着也得再循环体内定义它)?
完整一点的例子在这里:
int main ()
{
double data[10] = {1,2,3,4, 5,6,7,8,9,10};
double * v = (double *) malloc ( 2 * sizeof(double));
int i;
for (i = 0; i < 5; i++)
{
v = &data[2*i];
printf("%f\n", v[1]);
}
return 0;
}
N********n
发帖数: 8363
47
来自主题: Programming版 - difference between: char** p and char*p[] ??

What I mean is when you declare an array without either specifying its
size or initializing its content (which is what the topic suggests and
typical in function parameter declaration), it's basically a pointer.
Say a fucntion is defined as:
void foo (XXX a[])
"sizeof(a)" within this foo function forever produces "sizeof(XXX *)"
instead of the actual size of the parameter a.
b*********n
发帖数: 1258
48
#include
using namespace std;
void* strcopy(char* in_str){
char* out_str;
if(out_str=(char*)malloc(sizeof(in_str)+1)){
out_str=(char*)memcpy(out_str,in_str,sizeof(in_str)+1);
return out_str;
}else{
cout << "Insufficient Memory" << endl;
return NULL;
}
}
int main(int argc, char* argv[])
{
char* a="abcdefghijklmn";
cout << (char*)strcopy(a) << endl;
return 0;
}
B********s
发帖数: 3610
49
来自主题: Programming版 - How to get local hostname under linux?
Code is as below. after I got the actural local ip information (credit to
ansel), I got a correct hostname but it was truncated at the first period.
For example, it gives "abc" instead of "abc.cs.mit.edu"
How can I get the full hostname then? Please pay attention to "my code" part.
Thanks.
fd = socket(AF_INET, SOCK_DGRAM, 0);
memset(&ifr, 0, sizeof(ifr));
memcpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));
ioctl(fd, SIOCGIFADDR, &ifr);
sin_ptr = (struct sockaddr_in *) &ifr.ifr_addr;
myself = sin
b*********n
发帖数: 1258
50
来自主题: Programming版 - 又一道面试题,我是不是想多了?
sizeof(p)/sizeof(*p)不就是int array的size吗
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)