小编Pau*_*ulH的帖子

提升MSM仅处理内部转换

我正在使用新的Boost 1.44.0 MSM库来生成状态机.在这个状态机中有两类事件class1class2.class1事件可以由任一状态进行处理S1S2同时class2事件只能通过状态进行处理S2.

特殊class1事件upgrade_req请求从州S1到州的升级S2.

我在Boost :: MSM中实现了如下:

// State S1 and S2 allow any class1 events
struct class1 {};
// Only state S2 allows class2 events
struct class2 {};

// an upgrade request is a class1 event that requests an upgrade to state 2
struct upgrade_req : public class1 {};

struct MyFSM : public msm::front::state_machine_def< MyFSM >
{ …
Run Code Online (Sandbox Code Playgroud)

c++ boost state-machine boost-msm

5
推荐指数
1
解决办法
1969
查看次数

解释计算自由虚拟内存的二进制补码数学

我有一个适用于Windows Mobile 6.x的Visual Studio 2008 C++应用程序,我在这里计算给定进程可用的可用虚拟内存量.(我意识到它并没有考虑碎片.)我的代码看起来基本上是这样的:

MEMORY_BASIC_INFORMATION mbi = { 0 };

/// total free memory available to the process
DWORD free = 0;

/// base memory address for the given process index (2-33). 
DWORD slot_base_addr = process_index * 0x02000000;

/// look at each memory region for the process. 
for( DWORD offset = 0x10000; 
     offset < 0x02000000; 
     offset += mbi.RegionSize )
{
    ::VirtualQuery( ( void* )( slot_base_addr + offset ), 
                    &mbi, 
                    sizeof( MEMORY_BASIC_INFORMATION ) );

    if( mbi.State == MEM_FREE ) …
Run Code Online (Sandbox Code Playgroud)

c++ windows-mobile twos-complement

5
推荐指数
1
解决办法
305
查看次数

如何在可执行文件上设置MOTW

如何在从互联网上下载的可执行文件中设置MOTW(Web标记)?

c++ ntfs

5
推荐指数
2
解决办法
738
查看次数

将GetLastError()转换为异常

我有一个Visual Studio 2008 C++项目,Win32Exception在出现异常错误的情况下使用类.这个Win32Exception类看起来像这样:

/// defines an exception based on Win32 error codes. The what() function will
/// return a formatted string returned from FormatMessage()
class Win32Exception : public std::runtime_error
{
public:
    Win32Exception() : std::runtime_error( ErrorMessage( &error_code_ ) )
    {
    };

    virtual ~Win32Exception() { };

    /// return the actual error code
    DWORD ErrorCode() const throw() { return error_code_; };

private:

    static std::string ErrorMessage( DWORD* error_code )
    {
        *error_code = ::GetLastError();

        std::string error_messageA;
        wchar_t* error_messageW …
Run Code Online (Sandbox Code Playgroud)

c++ error-handling exception

5
推荐指数
1
解决办法
4309
查看次数

boost :: make_shared导致访问冲突

我有一个用于ARMV4I Windows Mobile 6的Visual Studio 2008 C++应用程序,我用它boost::shared_ptr<>来管理一个相当大的对象(4KB).不幸的是,boost::make_shared<>导致访问冲突异常.

我的代码:

struct Foo
{
    char a[ 4 * 1024 - 1 ];
};

int _tmain( int argc, _TCHAR* argv[] )
{
    boost::shared_ptr< Foo > f = boost::make_shared< Foo >(); // Access Violation
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

callstack异常:

test.exe!boost::detail::sp_ms_deleter<o>::sp_ms_deleter<o>(void) Line: 60, Byte Offsets: 0x18   C++
test.exe!boost::make_shared<o>(void) Line: 106, Byte Offsets: 0x5c  C++
test.exe!wmain(int argc = 1, wchar_t** argv = 0x01b40060) Line: 81, Byte Offsets: 0x18  C++
test.exe!mainWCRTStartup(HINSTANCE__* hInstance = 0x00000003, HINSTANCE__* …
Run Code Online (Sandbox Code Playgroud)

c++ boost windows-mobile

5
推荐指数
1
解决办法
903
查看次数

延迟加载MySQL连接器

我在Windows 7 x64上使用MySql 5.1.53和MySql Connector/Net 6.4.4进行Visual Studio 2008 C#.NET 3.5项目.在我的应用程序中,我查询我的数据库:

IQueryable<Zoo> my_query = from d in my_context_.MySet
                                  .Include("Foo")
                                  .Include("Bar")
                                  where d.Fuzz.Status == (int)Status.Pending
                                  orderby d.Order
                                  select d;

foreach (Zoo z in my_query)
{
    if (some_expression)
    {
        // Lazy load some more data from the query. This throws a 
        // MySqlException
        z.Something.Load();
    }
    else
    {
        // Lazy load some other data from the query. This also throws a 
        // MySqlException
        z.SomethingElse.Load();
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的例外是:

System.Data.EntityCommandExecutionException: An error occurred while executing the …
Run Code Online (Sandbox Code Playgroud)

c# mysql lazy-loading

5
推荐指数
1
解决办法
1528
查看次数

打印过程实时输出

我在Windows 7 x64系统上使用PHP 5.3.4和Apache 2.2.17.我希望我的PHP页面能够system实时向用户的浏览器输出调用结果.为此,我output_buffering=Off在php.ini中配置并创建了这段代码:

<?php
ob_implicit_flush(true);
ob_end_flush();
system('ping -n 10 www.google.com');
?>
Run Code Online (Sandbox Code Playgroud)

ping的结果是实时打印的,但是我的页面顶部也出现了PHP诊断错误和callstack:

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush in index.php on line 3
Run Code Online (Sandbox Code Playgroud)

如何更正或抑制此错误,我需要做什么?

更新 如果我改为ob_end_flush(),$a = 1/0;我会收到类似的错误,并且输出在所有浏览器中都是实时的.它是否与打印异常的方式有关?

php apache

5
推荐指数
1
解决办法
5999
查看次数

CDB没有显示WinDBG为callstacks所做的代码行

我使用的是WinDBG 6.12.0002.633 X86.

我遇到命令行调试器CDB的问题,并没有显示kkL命令的WinDBG相同的结果.

在WinDBG中,该k命令正确显示了callstack的代码行,其中kL命令正确地删除了该信息并仅显示了偏移量.

1:128:armce> k
Child-SP RetAddr  Call Site
761efaf4 78013cdc module_78010000!SomeModule::Foo+0xb4 [bar.cpp @ 268]

1:128:armce> kL
Child-SP RetAddr  Call Site
761efaf4 78013cdc module_78010000!SomeModule::Foo+0xb4
Run Code Online (Sandbox Code Playgroud)

在CDB,的结果kkL是相同的:

1:128:armce> k
Child-SP RetAddr  Call Site
761efaf4 78013cdc module_78010000!SomeModule::Foo+0xb4

1:128:armce> kL
Child-SP RetAddr  Call Site
761efaf4 78013cdc module_78010000!SomeModule::Foo+0xb4
Run Code Online (Sandbox Code Playgroud)

我能做些什么来让CDB k像WinDBG那样显示命令的代码行?

windbg postmortem-debugging

5
推荐指数
1
解决办法
791
查看次数

获取PostThreadMessage的boost :: thread的ID

我有一个使用Boost 1.47.0的Visual Studio 2008 C++项目,我需要将boost :: thread的本机Windows ID传递给PostThreadMessage.

在Windows Vista和7中,我会这样做:

DWORD thread_id = ::GetThreadId( mythread.native_handle() );
Run Code Online (Sandbox Code Playgroud)

这很好,但我还需要我的应用程序在GetThreadId不存在的XP中工作.

我发现boost:thread将线程ID值存储在boost :: thread :: id的私有数据成员中thread_data.我可以通过做一些讨厌的演员来达到这个目的:

boost::detail::thread_data_base* tdb = *reinterpret_cast< boost::detail::thread_data_base** >( &message_thread.get_id() );
DWORD thread_id = tdb->id;
Run Code Online (Sandbox Code Playgroud)

但是,我开始收到引用临时boost::thread::id对象的编译器警告.

warning C4238: nonstandard extension used : class rvalue used as lvalue
Run Code Online (Sandbox Code Playgroud)

有没有一个好方法来获取ID?看到我需要的数据非常令人沮丧,但却无法实现.

谢谢,PaulH

c++ windows boost boost-thread

5
推荐指数
1
解决办法
2327
查看次数

算法删除两组交集中的元素

我有一个Visual Studio 2008 C++ 03应用程序,我有两个标准容器.我想从一个容器中删除另一个容器中存在的所有项目(集合的交集).

这样的事情:

std::vector< int > items = /* 1, 2, 3, 4, 5, 6, 7 */;
std::set< int > items_to_remove = /* 2, 4, 5*/;

std::some_algorithm( items.begin, items.end(), items_to_remove.begin(), items_to_remove.end() );

assert( items == /* 1, 3, 6, 7 */ )
Run Code Online (Sandbox Code Playgroud)

是否存在可以执行此操作的现有算法或模式,还是需要自行编写?

谢谢

c++ algorithm

5
推荐指数
1
解决办法
2459
查看次数