我目前正在.Net Framework 2.0中用C#重写旧的VB6程序(不是我的选择,它是由公司决定的).在大多数情况下,事情进展顺利.该程序测量来自精密磨床的输入数据,并显示图形和刻度盘以显示精度.
最初的程序员是机械工程师,但不是软件工程师.该程序有效,但这里和那里有一些草率的代码.最值得注意的是,我遇到了一些GoTo语句.在必要时将事物放在一个循环中并且从中获得相同的功能非常容易.
我遇到了原始代码中的一个案例,然而,似乎GoTo不仅仅是模拟一个循环.它有几个不同的退出条件.它看起来像这样(不是实际的代码,只是我做的简短演示):
VB6代码
Public Sub Tick()
Dim condition1 As Boolean
Dim condition2 As Boolean
Dim testNumber As Integer
beginning: 'The GoTo label'
' (... Some Other Code Here ...)'
If condition1 = True Then
goto beginning
Else
' (... Do some calculation ...)'
End If
If condition2 = True Then
' (... Do some calculation ...)'
goto beginning
End If
Select Case testNumber
Case 1: '(... Some code ...)'
Case 2: '(... Some code ...)'
Case 3: …Run Code Online (Sandbox Code Playgroud) 我想使用std :: for_each将一系列字符串添加到组合框中.对象是类型的Category,我需要调用GetName它们.我怎样才能实现这一目标boost::bind?
const std::vector<Category> &categories = /**/;
std::for_each(categories.begin(), categories.end(), boost::bind(&CComboBox::AddString, &comboBox, _1);
Run Code Online (Sandbox Code Playgroud)
当前代码在尝试调用时失败CComboBox::AddString(category).这显然是错的.如何CComboBox::AddString(category.GetName())使用当前语法调用?
我从HttpClient获得了内容,但我不知道下一步要去哪里,以便解析我的JSON结果.另外,如何异步执行此操作以便我可以向用户显示等待对话框,并选择取消当前请求(不关心UI示例,如何设置HTTP类可取消)?
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://mysite/test.json");
try
{
HttpResponse response = client.execute(request);
// What if I want to cancel now??
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
}
Run Code Online (Sandbox Code Playgroud) 在阅读DirectWrite源代码时,我遇到了以下结构:
/// <summary>
/// Line breakpoint characteristics of a character.
/// </summary>
struct DWRITE_LINE_BREAKPOINT
{
/// <summary>
/// Breaking condition before the character.
/// </summary>
UINT8 breakConditionBefore : 2;
/// <summary>
/// Breaking condition after the character.
/// </summary>
UINT8 breakConditionAfter : 2;
/// <summary>
/// The character is some form of whitespace, which may be meaningful
/// for justification.
/// </summary>
UINT8 isWhitespace : 1;
/// <summary>
/// The character is a soft hyphen, often used to indicate hyphenation …Run Code Online (Sandbox Code Playgroud) 为了编写跨平台游戏,我需要哪些语言或库?我可以构建一个可以在所有平台上运行的游戏,还是我必须为每个平台重新编译?
在 Windows World 中,一个专用的渲染线程会循环类似于以下内容:
void RenderThread()
{
while (!quit)
{
UpdateStates();
RenderToDirect3D();
// Can either present with no synchronisation,
// or synchronise after 1-4 vertical blanks.
// See docs for IDXGISwapChain::Present
PresentToSwapChain();
}
}
Run Code Online (Sandbox Code Playgroud)
Cocoa 中的等价物是什么CAMetalLayer?所有示例都处理在主线程中完成的更新,使用MTKView(使用内部计时器)或CADisplayLink在 iOS 示例中使用。
我想控制整个渲染循环,而不是仅仅在某个非指定的时间间隔接收回调(如果启用了 V-Sync,理想情况下会阻止它)。
#include<iostream>
using namespace std;
class A
{
int a;
int b;
public:
void eat()
{
cout<<"A::eat()"<<endl;
}
};
class B: public A
{
public:
void eat()
{
cout<<"B::eat()"<<endl;
}
};
class C: public A
{
public:
void eat()
{
cout<<"C::eat()"<<endl;
}
};
class D: public B, C
{
};
int foo(A *ptr)
{
ptr->eat();
}
main()
{
D obj;
foo(&(obj.B)); //error. How do i call with D's B part.
}
Run Code Online (Sandbox Code Playgroud)
上面的foo调用是编译时错误.我想用obj的B部分调用foo而不使用虚拟继承.我怎么做.
此外,在虚拟继承的情况下,为什么偏移信息需要存储在vtable中.这可以在编译时自己确定.在上面的例子中,如果我们用D的对象传递foo,在编译时我们只能计算D的A部分的偏移量.
我有以下功能:
- (void)loadPdfFromPath:(NSString*)path
{
NSURL *pathUrl = [NSURL URLWithString:path];
_pdfDocument = CGPDFDocumentCreateWithURL((CFURLRef)pathUrl);
}
Run Code Online (Sandbox Code Playgroud)
从我带领相信会工作,因为你可以从一个区分的文件NSURL*到一个CFURLRef通过免费电话桥接.但是,此函数失败,我在日志中得到以下输出:
CFURLCreateDataAndPropertiesFromResource:错误代码-15.
注意:-15 = kCFURLImproperArgumentsError
但是,如果我创建一个实际的CFURLRef,它的工作绝对正常:
- (void)loadPdfFromPath:(NSString*)path
{
CGPDFDocumentRelease(_pdfDocument);
CFStringRef cgPath = CFStringCreateWithCString(NULL, [path UTF8String], kCFStringEncodingUTF8);
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, cgPath, kCFURLPOSIXPathStyle, 0);
_pdfDocument = CGPDFDocumentCreateWithURL(url);
CFRelease(url);
CFRelease(cgPath)
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?我很高兴在我的代码中保留第二个函数,但我宁愿知道为什么第一个函数失败了.
我正在开发VS-2010中的C++项目,我想安装一个Windows服务.我的问题是scinst是否默认存在于所有Windows 7和Windows 8中,是否可以使用以下代码在Windows中安装服务?或者我该怎么做才能实现它.
void CreateService(void)
{
system("sc create MyService binPath=c:\\abc.exe");
}
Run Code Online (Sandbox Code Playgroud)
期待您的回应.
鉴于以下情况:
class Foo
{
public:
void Increment()
{
_InterlockedIncrement(&m_value); // OSIncrementAtomic
}
long GetValue()
{
return m_value;
}
private:
long m_value;
};
Run Code Online (Sandbox Code Playgroud)
读取时是否需要内存屏障m_value?我的理解是,这_InterlockedIncrement将生成完整的内存屏障,并确保在发生任何后续加载之前存储该值。因此,从这方面来看,这听起来很安全,但是,m_value完全可以缓存,即可以GetValue()返回陈旧的值,即使在原子递增时也是如此?
Jeff Preshing 的优秀文章供参考:https://preshing.com/20120515/memory-reordering-caught-in-the-act/
其他上下文:
我正在关注一系列有关无锁编程的文章,特别是查看变量的用法unfinishedJobs以及此处的潜在实现HasJobCompleted:
https: //blog.molecular-matters.com/2015/08 /24/job-system-2-0-lock-free-work-stealing-part-1-basics/
void Wait(const Job* job)
{
// wait until the job has completed. in the meantime, work on any other job.
while (!HasJobCompleted(job))
{
Job* nextJob = GetJob();
if (nextJob)
{
Execute(nextJob);
}
}
}
Run Code Online (Sandbox Code Playgroud)
可以通过将 unfinishedJobs …