首页 \ 问答 \ JDK 1.6.x G1的经验(“垃圾第一”)(Experience with JDK 1.6.x G1 (“Garbage First”))

JDK 1.6.x G1的经验(“垃圾第一”)(Experience with JDK 1.6.x G1 (“Garbage First”))

我想知道在最新的JDK中使用G1垃圾收集器的经验是什么? 虽然在早期的JDK中代码没有改变并且行为正确,但我在程序中看到了抛出的NullPointerException异常。


I'd like to know what are the experiences with G1 garbage collector in newest JDK? I see NullPointerException thrown in my program, although code didn't change and behave correctly in earlier JDKs.


原文:https://stackoverflow.com/questions/986974
更新时间:2023-06-03 16:06

最满意答案

要回答你关于“这样做的标准方法是什么”的问题,我假设你的意思是传递成员函数和/或一般函数指针并用一些数据执行它们。 一些提供此功能的流行实现是:

  1. FastDelegate
  2. 的std ::功能
  3. 提振::函数

这真的取决于偏好和图书馆的选择。 就个人而言,我大部分时间都使用过FastDelegate,然后是std :: function。

我发布的所有链接都应该有教程信息,以帮助您启动并运行,并向您展示如何正确地传递和存储成员函数和/或一般函数指针。

以下是使用FastDelegate的示例:

class A 
{
public:
    // [1] This creates a delegate type. Can used for any function, 
    // class function, static function, that takes one int 
    // and has a return type of an int.
    typedef FastDelegate1< int, int > Delegate;

    // [2] Pass the delegate into 'A' and save a copy of it.
    A( const Delegate& delegate ) : _delegate( delegate ) { };

    void execute()
    {
        // [7]
        // Result should be 10!
        int result = _delegate( 8 ); 
    }

private:
    // [3] Storage to save the Delegate in A.
    Delegate _delegate;
};

class B
{
public:
    B() 
    {
        // [4] Create the delegate
        A::Delegate bDelegate;
        bDelegate.bind( this, &B::function );

        // [5] Create 'A' passing in the delegate.            
        _aPtr = new A( bDelegate );

        // [6] Test it out!! :) 
        // This causes `A` to execute the Delegate which calls B::function. 
        _aPtr->execute();
    }

    ~B() 
    {
        delete _aPtr; 
    }

    int function( int n )
    {
        return n+2;
    }

private:
    A* _aPtr;
};

To answer your question regarding "What's the standard method of doing something like this" I'll assume you mean passing member functions and/or general function pointers around and executing them with some data. Some popular implementations which provide this ability are:

  1. FastDelegate
  2. std::function
  3. boost::function

It really comes down to preference and library choice. Personally, I've used FastDelegate most of the time and then std::function after that.

All the links I posted should have tutorial information to get you up and running and show you how to properly pass and store member functions and/or general function pointers with ease.

Here's an example of using a FastDelegate with your example:

class A 
{
public:
    // [1] This creates a delegate type. Can used for any function, 
    // class function, static function, that takes one int 
    // and has a return type of an int.
    typedef FastDelegate1< int, int > Delegate;

    // [2] Pass the delegate into 'A' and save a copy of it.
    A( const Delegate& delegate ) : _delegate( delegate ) { };

    void execute()
    {
        // [7]
        // Result should be 10!
        int result = _delegate( 8 ); 
    }

private:
    // [3] Storage to save the Delegate in A.
    Delegate _delegate;
};

class B
{
public:
    B() 
    {
        // [4] Create the delegate
        A::Delegate bDelegate;
        bDelegate.bind( this, &B::function );

        // [5] Create 'A' passing in the delegate.            
        _aPtr = new A( bDelegate );

        // [6] Test it out!! :) 
        // This causes `A` to execute the Delegate which calls B::function. 
        _aPtr->execute();
    }

    ~B() 
    {
        delete _aPtr; 
    }

    int function( int n )
    {
        return n+2;
    }

private:
    A* _aPtr;
};

相关问答

更多
  • 要回答你关于“这样做的标准方法是什么”的问题,我假设你的意思是传递成员函数和/或一般函数指针并用一些数据执行它们。 一些提供此功能的流行实现是: FastDelegate 的std ::功能 提振::函数 这真的取决于偏好和图书馆的选择。 就个人而言,我大部分时间都使用过FastDelegate,然后是std :: function。 我发布的所有链接都应该有教程信息,以帮助您启动并运行,并向您展示如何正确地传递和存储成员函数和/或一般函数指针。 以下是使用FastDelegate的示例: class A ...
  • 是。 只要不直接或间接访问未初始化的成员或虚拟函数 ,因为对象尚未完全构建,就可以使用this指针在初始化列表中 。 对象child可以存储this Parent指针,供以后使用! Yes. It's safe to use this pointer in initialization-list as long as it's not being used to access uninitialized members or virtual functions, directly or indirectly ...
  • A::cbPtr类型需要指向A类的非静态成员函数的指针。 但是您尝试将指向非成员函数的指针分配给静态cbptr变量。 它们是两种不同的类型,这就是代码不能编译的原因。 从您的cbPtr typedef中删除A:: ,例如: #include //external callback function static void innerFunc(int i, float f) { printf("running inner function : %i %f\n", i, f); } ...
  • 找到特定类的所有当前对象真的没有好办法,但你可以使用whos来获取关于所有变量的结构,循环遍历这个并确定哪些具有你的属性然后修改 variables = whos; for k = 1:numel(variables) obj = eval(variables(k).name); if isobject(obj) && isprop(obj, 'color') obj.color = 'yellow'; end end 如果您正在寻找特定的类,则可以使用who ...
  • 我不认为你必须初始化数组,但我鼓励你这样做。 在你的情况下数组默认初始化的原因是你提供了一个构造函数,并且没有提到初始值设定项列表中的数据成员(cf. cppreference / default initialization ): 默认初始化在三种情况下执行: ... 3)当一个基类或一个非静态数据成员没有在构造函数初始化列表中被提及并且该构造函数被调用时。 因此,默认初始化将发生。 无论如何,为了表达您依赖数据成员为“零”,而不以其他方式强制未初始化的条目将被访问,我会使初始化显式化,例如 class ...
  • 除非是静态成员函数,否则不能将成员函数作为普通函数指针传递。 static int funct(myType); 当然,静态函数不能访问非静态的成员变量或函数,除非您将它们与另一个对象指针结合使用。 您还可以将传递给构造函数的指针类型更改为成员指针,但这更加复杂,除非您还传递该类型的对象,否则通常不会有用。 Subclass(char* t,Container* cp, int((Container::*)i)(myType),int a,int b,int c,int p) : Superclass ...
  • 你写了 values &getPointerToStruct(big *con) { values *return_vals; if(con->small_anchor->vals.val==10) return_vals=con->small_anchor->vals; return (&return_vals); } 我认为你想要的地方 values *getPointerToStruct(big *con) { values *return_vals ...
  • 如果呼叫机构的类型未存储在某个可访问的地方,则不能在呼叫站点调用未知类型的函数对象。 有两种选择: 如果您可以使用C ++ 11或boost,则可以使用std::function resp。 boost::function : class A { public: // ... void doSomeJob(int x) { functor(x); } private: std::function functor; // or boost::function ...
  • 如果对象isNew()没有ID,则无法在另一个上设置它的引用。 它的工作原理与此类似,因为数据库中尚不存在新对象。 如果您需要在此保存之前存在对象的信息,请使用afterSave hook和afterSave existed() 。 If the object isNew() is doesn't have an ID and you cannot set it's reference on another. It works like that because new object doesn't exi ...
  • 函数F()不是虚函数,这意味着函数调用将静态调度到指针/引用的静态类型中的版本,而不是让它在运行时找到对象的动态类型。 如果您符合您感兴趣的变体,则可以从指向Derived的指针访问相同的函数: pDerived->Base::F(); The function F() is not virtual, which means that the function call will be statically dispatched to the version in the static type of t ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。