删除pthread_t *(deleting pthread_t*)
我写了一个小的pthread多线程编程,我想清理我创建的pthred_t数组。 但是当我这样做时,我得到一个错误,即检测到了一个滑动条。 如何删除阵列,或者我根本不需要。 代码运行良好,没有释放内存,但在我看来,下面的代码导致(小)内存韭菜。 谢谢
pthread_t* threadNumber = new pthread_t (4); args var; var.matrixA=matrixA; var.matrixB=matrixB; var.matrixC=matrixC; var.alpha=alpha; var.beta=beta; var.cellCount=0; var.maxCells=cColumns*cRows; for (int i =0 ;i<4;++i) pthread_create(&threadNumber[i],&attr,matrixMultiply,(void *) (&var)); for(int i=0;i<4;++i) pthread_join(threadNumber[i],NULL); printMatrix(matrixA,aRows,aColumns); printMatrix(matrixB,bRows,bColumns); printMatrix(matrixC,cRows,cColumns); //delete threadNumber; //this caused a memory trash
I wrote a small pthread multithreadding programming and i wanted to clean up the pthred_t array which i created. But when I do it I get the error that a glib has been detected. How can I delete the array, or do I simply not need to. The code runs fine without the freeing of the memory but in my opinion the code below causes a (small) memory leek. Thanks
pthread_t* threadNumber = new pthread_t (4); args var; var.matrixA=matrixA; var.matrixB=matrixB; var.matrixC=matrixC; var.alpha=alpha; var.beta=beta; var.cellCount=0; var.maxCells=cColumns*cRows; for (int i =0 ;i<4;++i) pthread_create(&threadNumber[i],&attr,matrixMultiply,(void *) (&var)); for(int i=0;i<4;++i) pthread_join(threadNumber[i],NULL); printMatrix(matrixA,aRows,aColumns); printMatrix(matrixB,bRows,bColumns); printMatrix(matrixC,cRows,cColumns); //delete threadNumber; //this caused a memory trash
原文:https://stackoverflow.com/questions/13108886
最满意答案
我相信他说他想从他的代码中删除内联注释。
最快的方法是在文件中为UPGRADE_WARNING执行查找:并手动删除它们。
要么,
您可以创建一个新的.Net程序来遍历源目录中的每个.vb文件,并使用StreamReader读取它们,然后一次将它们写出一行到同一个文件中,然后省略包含UPGRADE_WARNING的任何行: 。
如果你采取第二种方式,那么你可以更好地完成更多的vb.net编码。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim FileName As String = "c:\form1.vb" Dim SourceFile As System.IO.FileInfo = New FileInfo(FileName) Dim SourceTextStream As System.IO.TextReader = SourceFile.OpenText() Dim SourceFileContent() As String = Split(SourceTextStream.ReadToEnd(), vbCrLf) SourceTextStream.Close() Dim CurrentSourceLine As String Dim CurrentSourceLineNumber As Long Dim DestStream As StreamWriter = New StreamWriter(FileName) Dim LogStream As StreamWriter = New StreamWriter(FileName + ".log") For Each CurrentSourceLine In SourceFileContent CurrentSourceLineNumber += 1 If InStr(CurrentSourceLine, "UPGRADE_WARNING") = 0 Then DestStream.WriteLine(CurrentSourceLine) Else ' Write to Log File LogStream.WriteLine("Line Skipped at number: " + CurrentSourceLineNumber.ToString()) End If Next DestStream.Close() LogStream.Close() End Sub
I believe he is saying that he wants to remove the inline comments from his code.
Fastest way is to perform a find in files for UPGRADE_WARNING: and remove them by hand.
Or,
You could create a new .Net program to iterate through each .vb file in your source directory and read them in using a StreamReader and then write them out 1 line at a time to the same file and as you go omit any lines containing UPGRADE_WARNING:.
If you do the second way you will be that much better for having done some more vb.net coding.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim FileName As String = "c:\form1.vb" Dim SourceFile As System.IO.FileInfo = New FileInfo(FileName) Dim SourceTextStream As System.IO.TextReader = SourceFile.OpenText() Dim SourceFileContent() As String = Split(SourceTextStream.ReadToEnd(), vbCrLf) SourceTextStream.Close() Dim CurrentSourceLine As String Dim CurrentSourceLineNumber As Long Dim DestStream As StreamWriter = New StreamWriter(FileName) Dim LogStream As StreamWriter = New StreamWriter(FileName + ".log") For Each CurrentSourceLine In SourceFileContent CurrentSourceLineNumber += 1 If InStr(CurrentSourceLine, "UPGRADE_WARNING") = 0 Then DestStream.WriteLine(CurrentSourceLine) Else ' Write to Log File LogStream.WriteLine("Line Skipped at number: " + CurrentSourceLineNumber.ToString()) End If Next DestStream.Close() LogStream.Close() End Sub
相关问答
更多-
VB和C语言哪个难一些?[2023-06-26]
vb -
VB6与VB.NET的差异有哪些?[2022-02-04]
.Net平台引入了很多先进的技术,导致了VB6和VB.Net之间产生了一个巨大的鸿沟 就语言功能上来讲,VB.net完全是为了.Net技术而生,具有更好的运行效率和更加强大的功能(某些方面甚至超过了C#) 从语法角度上来讲,VB.net成为了真正的OOP(面向对象语言),不但支持类的继承、派生,还支持委托、泛型等等更加高级的编程技术 如果你是从VB6升级到.net的话,建议要将VB.net当作一门新的语言来学。以VB6的经验来应用到VB.net上是会犯很多错误的 关于从VB6升级到VB.net的代 ... -
VB6与VB.NET的差异有哪些?[2022-10-11]
.Net平台引入了很多先进的技术,导致了VB6和VB.Net之间产生了一个巨大的鸿沟 就语言功能上来讲,VB.net完全是为了.Net技术而生,具有更好的运行效率和更加强大的功能(某些方面甚至超过了C#) 从语法角度上来讲,VB.net成为了真正的OOP(面向对象语言),不但支持类的继承、派生,还支持委托、泛型等等更加高级的编程技术 如果你是从VB6升级到.net的话,建议要将VB.net当作一门新的语言来学。以VB6的经验来应用到VB.net上是会犯很多错误的 关于从VB6升级到VB.net的代码变换问题 ... -
(VB.NET)'VB6'未声明。((VB.NET) 'VB6' is not declared. It may be inaccessible due to its protection level)[2022-05-04]
PixelsToTwips仅在32位项目中受支持。 请尝试以下操作,或使用Imports Microsoft.VisualBasic.Compatibility 。 请务必将Microsoft.VisualBasic.Compatibility作为参考。 Dim X As Single = Microsoft.VisualBasic.Compatibility.VB6.PixelsToTwipsX(eventArgs.X) Dim Y As Single = Microsoft.VisualBasic.Co ... -
有一个来自vb.net。 当您打开.vbp vb6项目时,它会询问您是否想自动将其转换为vb.net。 它做得不错,不包括第三方附加组件。 There is one that comes with vb.net. When you open a .vbp vb6 project, it asks if you would like to automatically convert it to vb.net. It does a pretty good job, exclusive of third part ...
-
在VB6中,颜色表示为Longs,而在VB.NET中,颜色表示为Structures。 资源 在Visual Basic 6.0中,颜色由Long类型的值表示; 在Visual Basic 2008中,颜色是Color类型。 在Visual Basic 6.0中,提供了八种标准颜色的常量; 在Visual Basic 2008中,有超过100种命名颜色。 小费 若要查找不是标准颜色的Visual Basic 6.0颜色的等效值,可以使用ColorTranslator类并将其传递给Visual Basic 6 ...
-
将vb6项目转换为VB.NET后,可以轻松删除警告消息(Easy way to remove warning messages after converting vb6 project to VB.NET)[2024-04-29]
我相信他说他想从他的代码中删除内联注释。 最快的方法是在文件中为UPGRADE_WARNING执行查找:并手动删除它们。 要么, 您可以创建一个新的.Net程序来遍历源目录中的每个.vb文件,并使用StreamReader读取它们,然后一次将它们写出一行到同一个文件中,然后省略包含UPGRADE_WARNING的任何行: 。 如果你采取第二种方式,那么你可以更好地完成更多的vb.net编码。 Private Sub Button1_Click(ByVal sender As System.Objec ... -
我经常把人们推荐给http://vb.net-informations.com/crystal-report/vb.net_crystal_report_step_by_step.htm 基本上你需要添加Crystal引用(你需要安装Visual Studio运行时的Crystal报告),添加一个CrystalReportViewer然后使用一些代码: Imports CrystalDecisions.CrystalReports.Engine Public Class Form1 Private ...
-
打开VB6项目时,我可以对所有打开的窗口做些什么吗?(Is there anything I can do about all the open windows when I open a VB6 project?)[2022-03-06]
如果您将MZ工具包添加到您的VB6 IDE中,该工具包包含“关闭所有窗口”按钮(以及其他许多方便的功能)。 If you add the MZ Toolkit to your VB6 IDE, that includes a "close all windows" button (along with numerous other handy things). -
您需要声明一个委托,如下所示: Delegate Sub DeviceStateChangedDelegate(ByVal param As Integer) 然后在SetupCallBacks方法内部,您需要创建和调用您的委托,如下所示: Public Sub SetupCallBacks() ' Declare and instantiate the delegate Dim MTUSCRADeviceStateChangedNotify As DeviceStateChangedDe ...