`
vyloy
  • 浏览: 78738 次
  • 性别: Icon_minigender_1
  • 来自: 佛山
社区版块
存档分类
最新评论
文章列表
#include <string.h> #include <stdio.h> int main() { int a [10 * 1024 * 1024]; a[0] = 1; return 0; } 上面的代码运行就会crash。 原因: ulimit -s 10240 可以看到linux配置的线程栈的大小为10M。 函数里面使用了两个大的数组,超出了linux线程栈大小配置的上限,而函数调用是需要栈的,当空间不足,导致越界,所以core掉。所以在函数中劲量少使用大的数据,而是使用堆分配内存。 为什么加上a[0] = ...
函数原型: void *memcpy(void *dest, const void *src, size_t n) void *memmove(void *dest, const void *src, size_t n) 两者的功能基本相同,唯一不同的是,当 dest 和 src 有重叠的时候选用不同的函数可能会造成不同的结果。 memcpy的原理是从src的低地址开始到高地址,单个字节复制,如果src与dest有重叠,并行src的地址低于dest的话,将会得不到想要的结果,如果src的址高于dest的话,则不会出现这种情况: 实例: #include <iostream&g ...
1. #:在宏展开的时候会将#后面的参数替换成字符串,如:           #define p(exp) printf(#exp);        调用p(hello)的时候会将#exp换成”hello” The # operator should not be confused with the null directive. Use the # operator in a function-like macro definition according to the following rules: A parameter following # operator in a fu ...
#include <iostream> #include <thread> #include <mutex> #include <chrono> std::mutex g_lock; void func() { g_lock.lock(); std::cout << "entered thread " << std::this_thread::get_id() << std::endl; std::this_thread::sle ...
先安装依赖项目: http://gcc.gnu.org/install/prerequisites.html 主要需要编译GMP、MPFR、MPC、ISL、glibc glibc与gcc一样,不能在源码目录下直接编译。 所以应该新建一个目录如obj,然后调用../src/configure yum install flex bison 设置环境变量LD_LIBRARY_PATH=/usr/local/lib,因为GMP、MPFR、MPC、ISL都默认装在里面。或者可以把/usr/local/lib添加到/etc/ld.so.conf里,再执行ldconfig。 减少编译时间可以在confi ...
首先去Oracle下载最新的版本 mkdir -p /opt/java/64 cd /opt/java/64 tar xf jdk-7u7-linux-x64.tar.bz2 chown -R root.root /opt/java chmod ugo+rx -R /opt/java sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.7.0_17/bin/java 200 --slave /usr/bin/javac javac /opt/java/jdk1.7.0_17/bin/javac --slav ...
Why Worry About Byte Order In general, the underlying byte order of the processor is completely transparent to the programmer. However, there can be a problem, for example, when data is exchanged with another system, since the other system may interpret multi-byte values differently. For example, s ...
Tcp传输数据分包不外乎3个方法: 定长数据包。 带数据长度的包头。 在数据包之间用换行之类的特殊符号分隔。 如果使用ObjectSerializationCodecFactory的ProtocolCodecFilter直接传输Java类对象的话,实际上会在要传输的数据前加上4个字节的来表示数据长度。关键代码如下: public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { if (!(mess ...
为什么需要boost::enable_shared_from_this? class cat{}; shared_ptr<cat> p(new cat); shared_ptr<cat> p2(p); class cat:public boost::enable_shared_frome_this{}; shared_ptr<cat> p(new cat); shared_ptr<cat> p2=p->shared_from_this(); 这两段代码看似没什么区别。但是如果你在程序里,比如在cat中 ...
public static void main(String[] a) { String target="abc"; String r; switch(target){ case "abc": r="cba"; break; default: case "def": r="fed"; } System.out.println(r); } Eclipse JDT Stack: 2, Locals: 4 0 ldc <Str ...
打开top,按shift+H。帮助文档说明:        -H : Threads toggle             Starts top with the last remembered 'H' state reversed.  When             this  toggle is On, all individual threads will be displayed.             Otherwise, top displays a  summation  of  all  threads  in  a             process. 就可以找出最 ...
http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html 17.3 引用 Thread.sleep causes the currently executing thread to sleep (temporarily cease execution) for the specified duration, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any m ...
card table marking技术虽然可以提高gc效率,但在高并发的情况下,会导致CPU缓存行的false sharing,从而可能会对吞吐量有较大负面影响。 可以开启-XX:+UseCondCardMark 开启这个功能后,card table marking,会在marking前判断一下,避免冗余的store操作。 参考:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7029167
当gc执行时,决定SoftReference回收有两个因素: SoftReference的timestamp 有多少空闲空间 在server模式下,会用-Xmx参数得到空闲空间大小。 在client模式下,会用当前heap最大空闲空间大小。 简单来说,server模式下会优先扩大heap大小,client模式下会优先回收垃圾。 SoftReference类中,有一个timestamp: public class SoftReference<T> extends Reference<T> { /* Timestamp clock, updated ...
动态得到类的实例,我们通常通过反射来得到。但有时候,类缺少默认构造方法,我们又不想传参来实例化,这时候怎么办呢? 我们还可以通过sun.reflect.ReflectionFactory来完成,例子如下: import java.lang.reflect.Constructor; import java.util.concurrent.ConcurrentHashMap; import sun.reflect.ReflectionFactory; import com.esotericsoftware.kryo.Kryo; public class Kryox exte ...
Global site tag (gtag.js) - Google Analytics