|
Luc Pattyn wrote: 1. how are you setting the callback?
My main form in the c# app implements an interface, ICaptureCallback, which looks like this:-
interface ICaptureCallback
{
void ReturnFrame(byte[] frameData);
}
The C++/CLI class that calls this takes an ICaptureCallback parameter in it's contstructor.
Luc Pattyn wrote: 2. what is (or would be) the prototype of the callback in native C++?
Not sure why this is relevant; the callback is implemented solely in managed code.
Luc Pattyn wrote: 3. who is allocating and freeing the (native?) buffer that the callback is assumed to consume?
The data originates in a native buffer from ffmpeg, but these lines of code:-
array<Byte>^ jpegData = gcnew array<Byte>(Width * Height * 3);
Marshal::Copy(IntPtr(pRgbFrame->data[0]),jpegData,0,Width * Height * 3);
m_callback->ReturnFrame(jpegData);
jpegData = nullptr;
which are from the C++/CLI class that does the call show that the data is Marshal.Copy'd into a managed byte array. Although I've not shown the code, I'm confident that the native buffer is properly freed.
Luc Pattyn wrote: 4. don't you close the file (m_outputWriter and m_outputFile)? without it, the stream grows bigger and bigger.
Because the objective of this app is to store the frames in a big binary file. Other code, which I've removed from the callback stored the offsets and frame sizes for later use. To close the file would stop the exact designed functionality of the app. Note, that the file is a disk file, not a memory stream, so should only get big on the disk, not take up much ram.
thanks for your interest.
Jon
|
|
|
|
|
Hi Jon,
I think I start to get the overall picture now.
Here are some thoughts:
1. your buffers are "large", i.e. larger than 85KB, hence allocated on the large-object-heap LOH which never gets compacted, and therefore is subject to fragmentation (unless all objects have the exact same size). In extreme cases fragmentation could mean your app is really using only a few megabytes, yet fails to allocate one more megabyte.
Remember: collections such as lists are implemented as arrays, not linked lists, so whenever their count exceeds the next power of two, the array gets reallocated with twice the size, potentially also invading the LOH.
2.
The line jpegData = nullptr; probably is not relevant since in the previous line (m_callback->ReturnFrame(jpegData); ) you passed the reference to another method, which could store it somehow, and hence keep the array alive.
3.
You may have a performance problem: with 5 frames per second, you need an overall throughput of 23MB/sec which you copy once with Marshal.Copy, copy once more with m_outputWriter.Write, and finally the system must dump to the disk in order for the memory to become available again. That could be beyond your system's capabilities; watch Task Manager and/or experiment with less data (smaller frames, or fewer frames per second, maybe skip every second frame).
4.
Maybe you could simplify things (and reduce the system load) by passing a ready-made buffer to your native code, rather than have it allocate, fill, copy and deallocate. That is how I have always done image processing in mixed environments.
If all the data needs to go through is generate natively and write to a managed file, you could do that with just one array, using it over and over.
Hope this helps. If you need more detailed discussions, I'd probably want to see ALL code relevant to allocating, pinning. copying and freeing buffers.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello,
I have two forms; one is the main form and the other the Delimiter form. The first form gets the file extension and location from the user. The second form is used when the user selects .txt files. The second form captures the delimiter of the .txt file then is closed when the "OK" button is clicked. Here is where I am having the problem. I need the delimiter info the user inputs, which is a text box on the second form, to be called in the connection string. I have tried a couple of things but the only delimiter I can get to work is when I hard code this into the connection. Can someone please help me? Here is what I have:
First form:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited(TAB)""";
Second form:
string GD;
GD = textBox1.Text;
What I would like to do is something like:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited["+ GD +")"; --This doesn't work
Thank you!
|
|
|
|
|
bwood2020 wrote: =Delimited["+ GD +")";
Try replacing '[' with '(' - it may help!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thank you for your reply!
Sorry, that was a typo on my part. I had ["+ GD +"]. GD doesn't show up in the popup but the name of the second form does (GetDelimiter). I used this as well but it throws the error:
GetDelimiter is a 'type' but is used like a 'variable'.
When I use GD it throws the error:
GD does not exist in the current context.
What am I doing worng here?
Thank you!
|
|
|
|
|
If I understand you correctly, you want to get a value from the second Form in the first?
If so, create a public property or method in the second Form, and call that from the first using the instance of the second Form.
string specialText = form2.TextIWant
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Yes, that is correct. I want to capture the value from the second form and use it in the first.
in the second form I have this:
public void textBox1_TextChanged(object sender, EventArgs e)
{
string GD;
GD = textBox1.Text;
}
then I am calling it in the first form with this:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited("+ GD +")";
Both methods were made public before posting. Should have mentioned that.
When I declare another string in the first it only allows me to write:
string GDS = GetDelimiter.GD
This throws an error:
Doesn't contain a definition for GD.
|
|
|
|
|
Keep a reference to the second form when you instanciate it and use that reference.
A simple example. Button on Form1, TextBox on Form2:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Form2 form2;
public Form1()
{
InitializeComponent();
form2 = new Form2();
form2.Show();
}
private void button1_Click(object sender, EventArgs e)
{
if (form2 != null)
MessageBox.Show(form2.GD);
}
}
}
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
}
public string GD
{
get;
set;
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Having a problem with get and set. The error I receive for:
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
}
public string GD
{
get;
set;
}
Error: get and set must declare a body because it is not marked abstract or extern.
I tried adding some code to get and set and I received this error:
public void textBox1_TextChanged(object sender, EventArgs e)
{
//GD = textBox1.Text;
}
public string GD
{
get { return GD; }
set { GD = value; }
}
Error:Make sure you do not have an infinite loop or infinite recursion.
Any ideas?
|
|
|
|
|
The problem is caused by your new public property. Change the case of the field references.
Change:
public string GD
{
get { return GD; }
set { GD = value; }
}
to:
public string GD
{
get { return gd; }
set { gd = value; }
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Sorry, I'm not following. As you can guess I am not a very good programmer. Just starting out and I thank you for your patience. I do not have any private fields in the second form. Do I need to declare gd as private? Something like:
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
gd = GD;
}
private string gd;
public string GD
{
get { return gd; }
set { gd = value; }
}
|
|
|
|
|
Almost right. Well worked out!
just a small change
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
gd = GD;
}
private string gd;
public string GD
{
get { return gd; }
set { gd = value; }
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
All right, it works!!! One more issue though. I placed a messageBox in the code on the first form and I am getting the correct string delimiter. So I know GD is storing this, however, when I go to call GetDelimiter.GD for the in the connection I get an ArgumentException was unhandled error:
Format of the initialization string does not conform to specification starting at index 85.
Here is the connection string:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited["+ GetDelimiterForm.GD +"]";
The error occures at:
OleDbConnection conTXT = new OleDbConnection(comString);
I know it has something to do with FMT=Delimited["+ GetDelimiterForm.GD +"]"; because if I hard code it it has no problems (FMT=Delimiter(TAB)""";). I have tried replacing "[" with "(" and that doesn't work. Any ideas on this one?
|
|
|
|
|
When you hard code it you are using slightly different syntax
Hard coded: FMT=Delimiter(TAB)
Using GetDelimiterForm: FMT=Delimited[......
Delimiter and Delimited, or is that just a typo?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I apologize, it was a typo. What I meant was
Hard Coded: FMT=Delimited(TAB) \\This works
Using GetDelimiterForm: FMT=Delimited["+ GetDelimiterForm.GD +"]\\This throws the error
|
|
|
|
|
It is the double quote thing for Extended Properties that is causing the problem.
In order to get a quotation mark within a literal string you have to 'escape them'
This means that the double quotes in the middle have to look like \"\", for them to be recognised as quotes within a string.
When this is all over look up Escape Characters for a better explanation.
In the mean time take a look at ADO Connection Strings[^], for some examples. Search in the article for 'Extended Properties' and you'll see what I mean.
Have a play.
Good Luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you Henry for all your help. I will look into this today.
|
|
|
|
|
Hi Henry,
I have read a couple articles on escape sequences and have tried to include the same line of code(just modified to fit what I need) and I still get errors. Maybe I am looking in the wrong place but when I try and use
Extended Properties=\"\"text;HDR=Yes;FMT=Delimited(" + gds + ");\"\";"; it says I need to add ";". But when I add one it tells me I need to add another. However, if I were to plug the line of code above into the code found in the Code Project page it seems fine. I think what is happening is that there is something wrong with the first part of the connection string, maybe the Source.
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";
Could you look at this one more time for me and point me in the right direction when you have time please? Here is the entire connection string:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=\"\"text;HDR=Yes;FMT=Delimited(" + gds + ");\"\";";
Thank you,
Brenton
|
|
|
|
|
I have found an article that is doing what I think you are trying to do.
Read text file (txt, csv, log, tab, fixed length)[^], it only uses one \" instead of two.
Have a look and see if it helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
That did it Henry. Thank you so much. Is there something I need to do is far as closing this out or giving you a rating? Let me know and I will come back.
|
|
|
|
|
Thanks for the thanks!
If you would just vote one of my posts as a 5, then people will know that your question has been answered.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Sorry, I was using automatic properties which may not be available in the version that you're working with.
Follow Henry's advice and use a private member variable that the property getter and setter accesses.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
There are two layers in my project. one is business layer,and the other is UI layer.
In UI layer, i invoke the method 'SaveInfo' of business layer. by the way ServiceActivator.GetService.
But i can't get 'newInfo' in UI layer.
and if i remove 'throw ex;' in 'SaveInfo' method. i could get it.
i don't know why.
do you know? how could i get newInfo if i want to throw Exception to UI layer.
pls. ths.
'SaveInfo' in Business layer:
public void SaveInfo(ref StudentInfo info,ref List<studentinfodetail> detailList,string strType)
{
try
{
...
info = newInfo;
detailList = newDetailList;
throw new MyException("Information already exist.");
...
}
catch(Exception ex)
{
throw ex;
}
}
the invoke code in UI layer:
try
{
...
mMyDs.SaveInfo(ref curInfo,ref curList,"Add");
...
]
catch(MyException mex)
{
textBox1.text = curInfo.Name;
}
catch(Exception ex)
{
}
MSN:msnadair@hotmail.com
Skype:skyadair
modified on Tuesday, May 12, 2009 8:52 PM
|
|
|
|
|
I have to say that returning to a calling process by throwing an exception is not the normal way to do it.
It would be better to give SaveInfo() a return type of bool and instead of throw new MyException use return true; .
Then in your calling code use
if (mMyDs.SaveInfo(ref curInfo,ref curList,"Add"))
{
}
else
{
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
No,i can't. i need to do this.
i should return the latest data from database if the info already exist. and the info may have different status, i should throw out the hint.
MSN:msnadair@hotmail.com
Skype:skyadair
|
|
|
|